DISTINCT ... ORDER BY
От | Nabil Sayegh |
---|---|
Тема | DISTINCT ... ORDER BY |
Дата | |
Msg-id | 3FA848D4.3070202@e-trolley.de обсуждение исходный текст |
Ответы |
Re: DISTINCT ... ORDER BY
Re: DISTINCT ... ORDER BY |
Список | pgsql-novice |
Hi all, I have built a query that mainly orders all columns. It shouldn't matter how it orders but FYI: I need to order by 1 given column and then by all others from 'left to right'. No problem so far. Then I want to return only 1 column (e.g. the 3rd) with duplicates removed _AND_ still in the same order like above. e.g.: myCol ----- a a c b b c b should return: myDistinctOrderedCol -------------------- a c b The problem is that DISTINCT complains about ORDER BY entries not being in the target list. Any idea ? Example: initial query: SELECT * FROM tab ORDER BY col_2='foo' DESC, col_1='bar' DESC, col_3='blah' DESC; Then something like: SELECT DISTINCT col3 FROM {initial query}; TIA -- e-Trolley Sayegh & John, Nabil Sayegh Tel.: 0700 etrolley /// 0700 38765539 Fax.: +49 69 8299381-8 PGP : http://www.e-trolley.de
В списке pgsql-novice по дате отправления: