Re: distinct

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: distinct
Дата
Msg-id Pine.BSF.4.10.10010091657440.23140-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на distinct  ("Otwell, Andrew (ISSAtlanta)" <AOtwell@iss.net>)
Ответы Re: distinct  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Tue, 3 Oct 2000, Otwell, Andrew (ISSAtlanta) wrote:

> I have attempted to run
> select distinct col1 from tablename;
> and it runs fine.
>
> When I run it in a real world environment:
> select distinct col1, col2, col3, col4 from tablename order by col1 desc,
> col2;
> It returns all the values from col1 which appears to be the same thing as
> not using distinct at all.
>
> Am I missing something? I'd like only distinct values on col1 and then I'll
> sort, include, or exclude the other columns.

That syntax above says get distinct values for all of col1, col2, col3,
col4, so (1,2,3,4) and (1,2,3,5) are not distinct and would both be
output.

There really isn't a spec way to do it, however,
 select distinct on (col1) col1, col2, col3, col4 from tablename;
would get you one row for each distinct col1, but it's undefined what
row that gets you.


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

Предыдущее
От: "Amy Antle"
Дата:
Сообщение: Question
Следующее
От: "Jono"
Дата:
Сообщение: Oracle to POSTGRESQL