Hi, I've got one table in DB on 4k notes with 2 columns(id and title) and one array on 4k elements. Both of them are full of equal data. What is the best way to sort it and insert in sorted order into another table in DB? Which way takes less resources to sort: using SQL or code it yourself using quick sort with array? Which strategy is better to use array or DB?
2 Answers
If you query for the data, then use order by and load it in the correct order in the first place.
If that data is available in your application without querying the other table, then do not do it and quicksort. You will save your database some work and it will probably be faster, especially since you're using java.
select * from ponies, the rows usually come in a predictable order (which may change e.g. if you add an index), but by definition, tables aren't sorted.