pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christof Glaser <gcg@gl.aser.de>
To: David Olbersen <dave@slickness.org>
To: pgsql-sql@postgresql.org
Subject: Re: Self-Referencing
Date: Thu, 29 Mar 2001 11:27:37 +0200
Message-ID: <01032911273700.00783@pinguin> (raw)
In-Reply-To: <Pine.LNX.4.31.0103281532530.11993-100000@bubbles.electricutopia.net>
References: <Pine.LNX.4.31.0103281532530.11993-100000@bubbles.electricutopia.net>

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



view thread (3+ messages)  latest in thread

Message-ID: <01032911273700.00783@pinguin>
Permalink:  ../01032911273700.00783@pinguin/
Also on:    postgresql.org/message-id/01032911273700.00783@pinguin

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: gcg@gl.aser.de, dave@slickness.org
  Subject: Re: Self-Referencing
  In-Reply-To: <01032911273700.00783@pinguin>
  References: <Pine.LNX.4.31.0103281532530.11993-100000@bubbles.electricutopia.net> <01032911273700.00783@pinguin>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox