MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 5th, 2004, 01:53 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
Post Sql query help...

Hello,

My table looks like this this (tablename: test):
---------------------------------------------
id name
1 A
2 C
3 B
4 D
5 Z
6 E
---------------------------------------------

When i execute the query (select name from test) i end up getting the rows in order (i.e. A, C, B, D, Z and E). Now, say i want these rows in exactly the reverse order. Can i formulate any query for the same? So, the new query should output the names in the order (E, Z, D, B, C and A) which is exactly the reverse order.

Thank you
Neville

Reply With Quote
  #2  
Old July 5th, 2004, 08:26 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Use the ORDER BY statement to order your returned records.
Code:
SELECT * FROM test ORDER BY id DESC
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old July 5th, 2004, 09:08 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
A little twist...

Thanks for the response. Anyway, this is not exactly what i was looking for. Lets also assume that the id's are all jumbled up too. So, the new table data say looks like this.

My table looks like this this (tablename: test):
---------------------------------------------
id name
2 C
6 E
3 B
5 Z
1 A
4 D
---------------------------------------------

Now, say i need the sequence D, A, Z, B, E and C in one query. Even the ids are NOT in order so order by DESC wont work here.

Thank you
Neville

Reply With Quote
  #4  
Old July 5th, 2004, 10:11 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Basically, you need to have another field that is orderable - i.e. using numbers or letters. I'm not sure what else you're expecting to do.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Sql query help...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway