readthefuckingmanual.net

[SOLVED] ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions

Error added: 2005-09-29T09:05:48Z

0 people waiting for the answer...

2 answers found.

Answer 1146 (85.71429% helpful)

If you have the following code
SELECT DISTINCT ON foo
FROM foobar
ORDER BY bar

it\'s asking you to do is to change it to this:
SELECT DISTINCT ON foo
FROM foobar
ORDER BY foo, bar

Select distinct uses the left most orderby clause to determine which of the duplicate rows it should keep.
Permalink

Answer 19 (66.666664% helpful)

In PostgreSQL, wrap the select in another select, and use the \"outer\" select to do the ORDER BY.
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: