This FAQ answer comes from Rob Taylor:
Ordering things on your page from your database is very easy - simply specify the columns you wish to order your query by using an ORDER BY clause. When using the ORDER BY clause, ordering happens by default in Ascending order (lowest to highest). To order in reverse (highest to lowest), use the keyword DESC.
Some examples of ordering using the ORDER BY clause can be seen below:
SELECT * from tblRockers ORDER BY ID
|
This will produce all the data in Ascending order on the ID column.
ID Band Category First Album 1 Jackson Browne Country/Rock 1969 1 Bonnie Raitt Country Rock 1974 1 Steppenwolf Classic Rock 1964 2 Ozzy Heavy Metal 1980 2 Rush Hard Rock 1969
SELECT * from tblRockers ORDER BY ID DESC
|
This will produce all the data in Descending order by ID.
ID Band Category First Album 2 Ozzy Heavy Metal 1980 2 Rush Hard Rock 1969 1 Jackson Browne Country/Rock 1969 1 Bonnie Raitt Country Rock 1974 1 Steppenwolf Classic Rock 1964
Now lets try to organize the data even more by adding other column names to the ORDER BY clause.
SELECT * from tblRockers ORDER BY ID,[First Album]
|
will return:
ID Band Category First Album 1 Steppenwolf Classic Rock 1964 1 Jackson Browne Country/Rock 1969 1 Bonnie Raitt Country Rock 1974 2 Rush Hard Rock 1969 2 Ozzy Heavy Metal 1980
Notice the data is ordered by ID and by First Album in Ascending order.
Lets look at Descending
SELECT * from tblRockers ORDER BY ID,[First Album] DESC
|
Gives us this:
ID Band Category First Album 2 Ozzy Heavy Metal 1980 2 Rush Hard Rock 1969 1 Bonnie Raitt Country Rock 1974 1 Jackson Browne Country/Rock 1969 1 Steppenwolf Classic Rock 1964
Happy Programming! |