Re: switching from mysql

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: switching from mysql
Дата
Msg-id web-507719@davinci.ethosmedia.com
обсуждение исходный текст
Ответ на Re: switching from mysql  (Brad Hilton <bhilton@vpop.net>)
Ответы Re: switching from mysql  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
Brad,

> 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?

In postgreSQL, you would use SELECT DISTINCT ON:

SELECT DISTINCT ON items.id *
FROM items JOIN store_items ON items.id = store_items.item_id;

However, you should consider that neither MySQL's implementation of
GROUP BY, nor SELECT DISTINCT ON, is ANSI-compliant SQL.  Therefore
portablility of either approach is limited.

-Josh

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Brett W. McCoy"
Дата:
Сообщение: Re: Perl and pgsql...
Следующее
От: Tom Lane
Дата:
Сообщение: Re: switching from mysql