TehGuy
June 15th, 2011, 02:27
The title basically explains the problem I'm having. I'm pretty new to SQL, so hopefully there's an easy way to do this.
My query looks like this right now:
$result = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 15");
It selects the biggest 15 dates from the table, sorted in descending order. After I get the 15 biggest dates, I want to re-sort them in ascending order. I'm not sure how to do that really. I could always make a temporary table, copy the data to it, then select from THAT table and sort it the way I want, but that seems hugely inefficient to me. I also thought about a 2-dimensional array then sorting the array by the date, but I'm hoping there's an easy way to do this with MySQL.
Any ideas how to select a limited number of the biggest values from a table, then sort it?
My query looks like this right now:
$result = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 15");
It selects the biggest 15 dates from the table, sorted in descending order. After I get the 15 biggest dates, I want to re-sort them in ascending order. I'm not sure how to do that really. I could always make a temporary table, copy the data to it, then select from THAT table and sort it the way I want, but that seems hugely inefficient to me. I also thought about a 2-dimensional array then sorting the array by the date, but I'm hoping there's an easy way to do this with MySQL.
Any ideas how to select a limited number of the biggest values from a table, then sort it?