sqlite - Sort comments by rating for the top two rows of the result and the rest by date? -
let's have table of comments, so:
--------------------------- | comment | date | rating | --------------------------- | | 1 | 1 | --------------------------- | b | 4 | 3 | --------------------------- | c | 7 | 2 | --------------------------- | d | 1 | 10 | --------------------------- | e | 3 | 20 | ---------------------------
i want sort table 2 rated comments appear @ top of result, independently of date, , rest of comments sorted date in descending order. results should this:
--------------------------- | comment | date | rating | --------------------------- | e | 3 | 20 | --------------------------- | d | 1 | 10 | --------------------------- | c | 7 | 2 | --------------------------- | b | 4 | 3 | --------------------------- | | 1 | 1 | ---------------------------
is possible?
you 2 sql-queries. first 1 selects 2 highest commands.
select comment, date, rating comments order rating desc limit 2
and can show others , order them date. aren't saving id comments table? if yes, select id in above query , in second query select comments, ordered date, don't have id previous query.
Comments
Post a Comment