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@math.tu-freiberg.de> /| \__
Network admin, systems programmer /_|____\
_/\ | __)
$ ./configure \\ \|__/__|
checking whether build environment is sane... yes \\/___/ |
checking for AIX... no (we already did this) |