<div>Thanks a lot Birgit, works just fine.</div>
<div> </div>
<div>Regards</div>
<div> </div>
<div>Julio Almeida<br><br></div>
<div class="gmail_quote">On Thu, Mar 17, 2011 at 8:50 AM, Birgit Laggner <span dir="ltr"><<a href="mailto:birgit.laggner@vti.bund.de">birgit.laggner@vti.bund.de</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div text="#000000" bgcolor="#ffffff">Hi Júlio,<br><br>you could use<tt> DISTINCT ON</tt>:<br><br>select distinct on (point_id) point_id, line_id, distance from worktemp.distances2streets order by point_id, distance;<br>
<br>This selects for every point_id the first row of every point_id group. Since you have ordered by distance too, the shortest distance is always on top of the list and will therefore be selected.<br><br>Regards,<br><br>
Birgit. 
<div>
<div></div>
<div class="h5"><br><br>On 16.03.2011 12:54, Júlio Almeida wrote: </div></div>
<blockquote type="cite">
<div>
<div></div>
<div class="h5">
<p>Hello,</p>
<p>I have a table with point_id, line_id, and distance (from point to line).<br>I need to create a new table with the record for the shortest distance for<br>each point.<br>I have tried:</p>
<p>select point_id,<br>line_id,<br>min(distance)<br>from worktemp.distances2streets group by point_id;</p>
<p>but i get the message:</p>
<p>ERROR:  column "distances2streets.line_id" must appear in the GROUP BY<br>clause or be used in an aggregate function<br>LINE 2: line_id,<br>       ^</p>
<p>********** Erro **********</p>
<p>ERROR: column "distances2streets.line_id" must appear in the GROUP BY clause<br>or be used in an aggregate function<br>Estado de SQL:42803<br>Carácter:18</p>
<p><br>Any suggestion?</p>
<p>Thanks</p></div></div><pre><fieldset></fieldset>
_______________________________________________
postgis-users mailing list
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a>
</pre></blockquote></div><br>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br>