From: | Helge Bahmann <bahmann(at)math(dot)tu-freiberg(dot)de> |
---|---|
To: | Brad Hilton <bhilton(at)vpop(dot)net> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: switching from mysql |
Date: | 2001-11-16 17:26:10 |
Message-ID: | Pine.LNX.4.21.0111161822060.30595-100000@lothlorien.stunet2.tu-freiberg.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On 16 Nov 2001, Brad Hilton wrote:
> The example I gave was a simple one to demonstrate my problem. Let me
> give a better example. Let's say I have 3 tables: items, stores, and
> store_items. 'store_items' maps items to stores. If I want to select
> all items that are in at least one store, I currently do:
>
> select items.* from items, store_items where items.id =
> store_items.item_id group by items.id
>
> Is there a better way to do this query?
SELECT DISTINCT ON (items.id) items.* FROM items
JOIN store_items ON store_items.id = items.id
regards
--
Helge Bahmann <bahmann(at)math(dot)tu-freiberg(dot)de> /| \__
Network admin, systems programmer /_|____\
_/\ | __)
$ ./configure \\ \|__/__|
checking whether build environment is sane... yes \\/___/ |
checking for AIX... no (we already did this) |
From | Date | Subject | |
---|---|---|---|
Next Message | Brett W. McCoy | 2001-11-16 18:03:38 | Re: Perl and pgsql... |
Previous Message | Brad Hilton | 2001-11-16 16:55:27 | Re: switching from mysql |