By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,809 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,809 IT Pros & Developers. It's quick & easy.

I am a newbie to mysql.plz help!.How to order the records in a table such that.......

P: 28
How to order the records in a table such that the elements in a field strating with a particular alphabet apper first.

ie.,the elements in the field names are as follows:

amar
Bob
joy
mana
sana
xena

I want it as: If 'm' is my input then 'mana' must apper first but all the records must also appear.

something like this:
mana
sana
xena
amar
Bob
joy.

Hoping that anyone of you will help me>>>>>>>..

Thanks i advance.
-ram
Dec 15 '06 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
Use a UNION to append the rows >= criteria with the rows < criteria, as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table 
  2.       WHERE SUBSTR(name,1,1) >= 'M' 
  3.       UNION 
  4.       SELECT * FROM table 
  5.       WHERE SUBSTR(name,1,1) < 'M';
  6.  
Ronald :cool:
Dec 18 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.