Timeline for Select Distinct on subset of columns, name different set of columns to return
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 26, 2015 at 6:11 | history | edited | Stevie | CC BY-SA 3.0 |
formatting
|
Jun 26, 2015 at 6:09 | comment | added | Stevie |
I think it is useful for Tom to have order by to sort rather than prevent a random selection between multiple rows. There probably aren't many cases where you want it to choose randomly! I edited the post to reflect that.
|
|
Jun 26, 2015 at 6:07 | comment | added | ypercubeᵀᴹ |
Yes my bad, sorry. If there is an order by, the first columns must match the columns of the distinct on , this is the restriction.
|
|
Jun 26, 2015 at 6:06 | history | edited | Stevie | CC BY-SA 3.0 |
adding detail
|
Jun 26, 2015 at 6:00 | comment | added | Stevie | @ypercube - Trying to clarify what's in the docs, it says that, "Note that the "first row" of each set is unpredictable unless ORDER BY is used to ensure that the desired row appears first." | |
Jun 26, 2015 at 5:59 | comment | added | Tom Doe | @ypercube that's definitely not true. I ran the query in postgres just now to confirm, and it ran successfully without order by. | |
Jun 26, 2015 at 5:57 | comment | added | Stevie |
@ypercube strange, I just tested this in Postgres and order by wasn't required.
|
|
Jun 26, 2015 at 5:56 | vote | accept | Tom Doe | ||
Jun 26, 2015 at 5:56 | comment | added | Tom Doe | Oh wow, didn't realize I was that close! This totally works (and the ORDER BY is neat, but unnecessary for what I need) | |
Jun 26, 2015 at 5:56 | history | edited | ypercubeᵀᴹ | CC BY-SA 3.0 |
added 204 characters in body
|
Jun 26, 2015 at 5:55 | comment | added | Stevie | If Tom cares about order, yea, then 'order by' would be important, but if they just wants the first entry for whatever reason, I think this would work. | |
Jun 26, 2015 at 5:50 | history | answered | Stevie | CC BY-SA 3.0 |