Order SQL records with same value by second criteria
I order some records by their value. If two records have the same value i want to order those two records by their date. For example:
record1 34 1.1.2000
record2 26 3.4.2000
record3 26 2.4.2001开发者_如何学Python
record4 76 1.5.2000
This should be ordered like this:
record4 76 1.5.2000
record1 34 1.5.2000
record3 26 2.4.2001
record2 26 3.4.2000
How can i manage this in SQL?
Like this:
SELECT *
FROM myTable
ORDER BY Value, Date
Each of these can also have an ASC/DESC specifier:
SELECT *
FROM myTable
ORDER BY Value ASC, Date DESC
Here is a link to MSDN, describing the syntax of the ORDER BY
clause.
SELECT * FROM records ORDER BY field1, field2
Just add the second order by column to the ORDER BY clause:
SELECT field1, field2, field3 FROM table ORDER BY value, date
精彩评论