News for hackers. Stuff that matters.
Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by helge9210 on Sunday February 02, 2025 @01:30AM (#42906509)
To have the first element, you have to describe a relation of order. It's not ordered by default.
Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by calmbonsai on Sunday February 02, 2025 @02:25AM (#42906821)
True, but even going all the way back to E.F. Codd, there's "cheating" involved with all sorts of implicit sorting.

Even now, the default behavior of SQLite is still "undefined" if a Select column doesn't appear in Group By. Well, to be precise it's a single "arbitrary chosen row" used to sort the results. https://www.sqlite.org/lang_select.html#resultset

I'm not bagging on SQLite here (I love it!), but I am bagging on SQL 'cuz EVERY implementation must make far too many of these sorts of Faustian bargains.

Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by disgruntledphd2 on Sunday February 02, 2025 @04:02AM (#42907317)
That sqlite one is really annoying, many other dialects give you an error.
Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by cyberax on Sunday February 02, 2025 @02:11AM (#42906740)
Actually, you don't have to. Any first element would do, even if it's a random one.

It's perfectly possible to do `SELECT * FROM blah LIMIT 1`, after all.

Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by _dain_ on Sunday February 02, 2025 @04:12AM (#42907378)
You can use ANY_VALUE to get an arbitrary value from a GROUP BY. There's also FIRST_VALUE for a window function (though that requires you specify an order).
Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by cyberax on Sunday February 02, 2025 @04:13PM (#42911888)
This is a non-standard extension, and it also doesn't allow the selection of the _first_ element in a group. Even if the group is actually ordered.
Re:SQL or Death? Seminar Series – Spring 2025 – Carnegie Mel... by cyberax on Sunday February 02, 2025 @04:14PM (#42911900)