News for hackers. Stuff that matters.
Re:User-defined Order in SQL by cthor on Wednesday March 21, 2018 @03:54AM (#16636276)
SELECT * FROM list ORDER BY pos LIMIT 3

If there's an index on pos, there's no cost to the sort.

Re:User-defined Order in SQL by Svip on Wednesday March 21, 2018 @03:58AM (#16636292)
Sorry, but that's just one user. Assume we have 1000 users, 800 of which have at least one item in the `items` table.

Now I want a full select of those 800 users with their first three to-do items in neat columns next to the user.

Your select doesn't do that.

Re:User-defined Order in SQL by cthor on Wednesday March 21, 2018 @06:06AM (#16636729)
Ah, ok, I misread. Yeah, that requires a subquery then, but not because of floats being unsuitabe for sorting, but because you're doing a 1-to-many thingy in a 1-to-1 way by hardcoding 3 columns. It's like writing

   items[0].text + items[1].text + items[2].text
In code to simplify it, instead of

   items.slice(0,2).map((e) => e.text).concat('');
The former mostly works, but it's definitely not elegant. And you have to be sure the number of items being 3 is set in stone.