SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 New row goes above other rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tkotey
Yak Posting Veteran

75 Posts

Posted - 11/02/2010 :  03:22:02  Show Profile  Reply with Quote
I created a table but when I add a new data it goes above other rows

E.g.


June	2010	1658700.81	1369635.52	
September	2010	1840488.63	1247912.33	
July	2010	1747470.53	1346944.29	7767173.75 
August	2010	1759271.99	1163199.45	8288671.96 


Instead of

June	2010	1658700.81	1369635.52		
July	2010	1747470.53	1346944.29	7767173.75 
August	2010	1759271.99	1163199.45	8288671.96
September	2010	1840488.63	1247912.33


Note "September" row is supposed to be at the end
It happens all the time

Kristen
Test

United Kingdom
22431 Posts

Posted - 11/02/2010 :  03:40:08  Show Profile  Reply with Quote
There is NO implied order in a relational database. To retrieve rows in a specific order you need to use the ORDER BY clause.

Sadly SQL will "most of the time" retrieve data in a given, repeatable, order and you won't know you have a problem until it doesn't! (A reason SQL might not is if half your data happens to be in memory from another query, SQL may work on that data first whilst it waits for other data to be fetched from disk - then, if your query does NOT have an order By clause, you may get the data that was in memory first, followed by the data retrieved from disk)
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 11/02/2010 :  04:22:37  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
So, always use ORDER BY clause in the SELECT statement if you want to get data in a particular order

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tkotey
Yak Posting Veteran

75 Posts

Posted - 11/02/2010 :  04:31:25  Show Profile  Reply with Quote
quote:
Originally posted by Kristen

There is NO implied order in a relational database. To retrieve rows in a specific order you need to use the ORDER BY clause.

Sadly SQL will "most of the time" retrieve data in a given, repeatable, order and you won't know you have a problem until it doesn't! (A reason SQL might not is if half your data happens to be in memory from another query, SQL may work on that data first whilst it waits for other data to be fetched from disk - then, if your query does NOT have an order By clause, you may get the data that was in memory first, followed by the data retrieved from disk)




Thanks Kristen. Your suggestions gave me an idea of which I implemented and it worked.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000