View previous topic :: View next topic |
Author |
Message |
TheDrummer
Joined: 11 Oct 2004 Posts: 4
|
Posted: Thu Oct 28, 2004 9:16 am Post subject: Ordering columns in SQL? |
|
|
Hi,
I have a SQL table called Sales with several colums, including OrderDate and Amount. I want to select everything from the Sales table, but I want it ordered by OrderDate first and then by Amount. So if you have 3 sales today, and 2 yesterday the result will look like:
10/27/2004 $150.00
10/27/2004 $300.00
10/28/2004 $100.00
10/28/2004 $120.00
10/28/2004 $130.00
I'll need help with this please.
Thanks,
John |
|
Back to top |
|
|
administrator Site Admin
Joined: 01 Oct 2004 Posts: 183
|
Posted: Thu Oct 28, 2004 1:12 pm Post subject: |
|
|
The following SQL statement will do:
Code: |
SELECT * FROM Sales ORDER BY OrderDate, Amount
|
This way you sort by both columns, but the first one has higher priority.
Cheers _________________ Peter
ASP & ASP.NET Articles and Tutorials |
|
Back to top |
|
|
TheDrummer
Joined: 11 Oct 2004 Posts: 4
|
Posted: Thu Oct 28, 2004 1:21 pm Post subject: |
|
|
Thanks a lot man! |
|
Back to top |
|
|
rose
Joined: 21 Feb 2006 Posts: 29
|
Posted: Sun Feb 26, 2006 4:59 pm Post subject: |
|
|
You can also add an ASC or DESC on to the end of that, to notify of ascending or descending order.
I may have got those abbreviations wrong, so check up on it. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|