I have a table with categories:
ID Category
"1","Baking"
"3","Family"
"4","Entertaining"
"5","Children"
"6","Desserts"
Now I would like to order the result of the select statement to
ID Category
"4","Entertaining"
"3","Family"
"1","Baking"
"5","Children"
"6","Desserts"
for example. In MySQL, you'd do it like this:
SELECT * FROM CATEGORIES ORDER BY FIELD (ID, 4,3,1,5,6);
How would you do it in SQLite though? I don't have an "order by" field.
Why not?
If it is because the sort order is application sepcific then do the sort in the application rather than in the database.
If it is because the sort order is specific to just this one query then encode it in the query HOWEVER I strongly suggest you make this transparent to the calling application e.g. (Standard SQL syntax):
If the sort order is used by multiple queries and/or applications then add it to a column in a table in the database then use that column in your query.
A second way of doing it (the first one being with
CASE WHEN ... THEN END
as already stated in other answers) is: