Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds,

Am working on sqlserver 2005 database.

I have one Table(Departments) In this I have one column Id.

This Id column is not arranged properly. In this i have 60 Ids (from 1 - 60)
This are not arranged properly, so I need to arrange properly from 1 to 60 in ascending order,

Please can you help me thanks.
Posted

1 solution

Easy:
SQL
SELECT * FROM Departments ORDER BY Id ASC
 
Share this answer
 
Comments
Ranjith Reddy CSE 18-May-13 3:57am    
ya, its fine after executing ur query.

But after executing this query Select * from Departments....it is same as old one.

Please help
OriginalGriff 18-May-13 4:18am    
SQL server is under no obligation to return information in any particular order unless you explicitly tell it that that is what you want. It returns rows in whatever order is efficient and reasonable for it - normally, that means means in the order in which they were inserted to the database, but that is not in any way guaranteed, since it can re-use old record space when you delete records to make the size of the database smaller. It can also reorder things when it compacts the database if that gives it more efficient processing.
If you want records returned in any specific order, then you must explicitly ask for it with an ORDER BY clause of some form.
Garth J Lancaster 18-May-13 4:12am    
'OG' gave you very good help - you even acknowledged his query with the 'order by Id ASC' on the end worked. So why are you going back to your old query without the order by clause - it makes NO SENSE

You MUST add the 'ORDER By Id ASC' to your SQL to get the results you need.
Ranjith Reddy CSE 18-May-13 4:50am    
Just i want to run in sql database.
OriginalGriff 18-May-13 5:07am    
Sorry, but I don't understand that.
Would you mind trying again, but explain in more detail?
It may help if you try to write it in your native language, then use Google Translate to convert it to English?

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