ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ordering columns in SQL?

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL)
View previous topic :: View next topic  
Author Message
TheDrummer



Joined: 11 Oct 2004
Posts: 4

PostPosted: Thu Oct 28, 2004 9:16 am    Post subject: Ordering columns in SQL? Reply with quote

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
View user's profile Send private message
administrator
Site Admin


Joined: 01 Oct 2004
Posts: 183

PostPosted: Thu Oct 28, 2004 1:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
TheDrummer



Joined: 11 Oct 2004
Posts: 4

PostPosted: Thu Oct 28, 2004 1:21 pm    Post subject: Reply with quote

Thanks a lot man!
Back to top
View user's profile Send private message
rose



Joined: 21 Feb 2006
Posts: 29

PostPosted: Sun Feb 26, 2006 4:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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

SQL Tutorial