Re: Self-Referencing - Mailing list pgsql-sql

From Christof Glaser
Subject Re: Self-Referencing
Date
Msg-id 01032911273700.00783@pinguin
Whole thread Raw
In response to Self-Referencing  (David Olbersen <dave@slickness.org>)
List pgsql-sql
On Thursday, 29. March 2001 01:38, David Olbersen wrote:
[snip]
>   SELECT
>     building_id,
>     num_buildings,
>     (
>       SELECT count( building_id )
>       FROM   building_portals
>       WHERE  building_id = THIS.building_id
>     )
>   FROM buildings;

Try this query (untested), using table aliases:

SELECT b.building_id, b.num_buildings,  ( SELECT count( bp.building_id )     FROM building_portals bp    WHERE
bp.building_id= b.building_id ) FROM buildings b;
 

You could also write <table>.<field> instead.

Hope that helps.

Christof
--          gl.aser . software engineering . internet service      http://gl.aser.de/  . Planckstraße 7 . D-39104
Magdeburg
Tel. +49.391.7 44 77 10 . Fax +49.391.7 44 77 13 . Mobil 0177.77 92 84 3


pgsql-sql by date:

Previous
From: Peter Mount
Date:
Subject: Re: Calling Java from psql (was Re: requesting help)
Next
From: Peter Mount
Date:
Subject: Re: Calling Java from psql (was Re: requesting help)