I am currently running this query:
SELECT t.videolink, t.userid, t.tag
FROM (SELECT * FROM tagstrend ORDER BY timestamp DESC) AS t
WHERE t.timestamp > ?
GROUP BY t.tag
ORDER BY SUM(t.tagcount) DESC
LIMIT ?, 20;
What I am doing is reversing the order of the table that I am selecting from before I run the rest of the query because when the I use “GROUP BY” I need that to take the top result which is the most recent row in the database.
However doing this will take a hit on the performance/speed of the query because it needs to reverse the order of the table before it can query it.
My question is, is there a way to set the default order of the table to be reversed? Because I will always be SELECTing from this table in reverse order.
Unless someone knows a way of grouping by the most recent row in the database?
“However doing this will take a hit on the performance/speed of the query because it needs to reverse the order of the table before it can query it.”
I don’t think that is true. Order By …. ASC and Order By …. DESC should have the same performance. Test it and see.