Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 New row goes above other rows

Author  Topic 

tkotey
Yak Posting Veteran

75 Posts

Posted - 2010-11-02 : 03:22:02
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

22859 Posts

Posted - 2010-11-02 : 03:40:08
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

22864 Posts

Posted - 2010-11-02 : 04:22:37
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 - 2010-11-02 : 04:31:25
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
   

- Advertisement -