<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Carsten,<br>
<br>
What you need is a *left join* :<br>
<pre><code>select grid.gid, count(kioskdhd3.geom) AS totale
FROM grid
LEFT JOIN kioskdhd3
ON st_contains(grid.geom,kioskdhd3.geom)
GROUP BY grid.gid;</code></pre>
Note that I changed the * in count to a column from your points
table because you only want to count when you have a non-null
value in your points table.<br>
<br>
Regards,<br>
Tom<br>
<br>
On 16-3-2013 16:53, Carsten Hogertz wrote:<br>
</div>
<blockquote cite="mid:5144955C.9010405@gmail.com" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<div class="post-text" itemprop="description">
<p>I've got a simple problem: I want to count the number of
points within a set of polygons.</p>
<p>I have a SQL already but it only gives back the gid of the
polygone that actually contains points.</p>
<p>My tables: a polygon layer with 19.000 rows and a point layer
with 450 rows.</p>
<p>The following SQL </p>
<pre><code>select grid.gid, count(*) AS totale FROM grid, kioskdhd3 WHERE
st_contains(grid.geom,kioskdhd3.geom) GROUP BY grid.gid;
</code></pre>
<p>return only some 320 polygons that actually contain points.
But I want all polygons returned, even thought the number of
points is 0.</p>
<p>Of course it has to do with my WHERE-clause. Where do I have
to put in my st_contains?</p>
<p>Thank you Carsten</p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
postgis-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a>
</pre>
</blockquote>
<br>
</body>
</html>