Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys
I m working on a project where i have to download the sorted data

I have to sort the data on basis of phone number's starting 3 digit.

SELECT * from table where substring(phone_number, 1, 3)='256';

please resolve if there is any error in this query or tell me the query to get starting 3 digit.
Thank u in advance
Posted

1 solution

Your example does not sort the data it only selects records that have phone_number starting with 256.

Use ORDER BY clause to sort the resulting data.

SELECT * from table ORDER BY substring(phone_number, 1, 3);

Or

SELECT * from table ORDER BY Left(phone_number, 3);
 
Share this answer
 
v3
Comments
[no name] 25-Dec-15 9:37am    
Good hint, a 5.
Member 11874141 25-Dec-15 23:47pm    
That's not working
Michael_Davies 26-Dec-15 3:11am    
In what way, what results do you get compared to your original, show us.

If you want help just saying "that's not working" will get you nowhere, remember we can not see your screen, provide information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900