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
 General SQL Server Forums
 New to SQL Server Programming
 Order By

Author  Topic 

KG07
Starting Member

8 Posts

Posted - 2009-03-16 : 15:57:48
I am producing a query where I am unioning several databases, and producing lists of numeric data. The data is automatically sorting itself descending without me using an order by clause. The separate databases are different dates, so I want it to give me the data organized by how I entered it (chronologically). How do I program that so that it produces the data out in the same order I put it in?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-03-16 : 16:30:31
There is nothing like "order in which I put in". data is stored in some random order on data pages. If you need the data to be in a particular order you need to use appropriate ORDER BY clause.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

KG07
Starting Member

8 Posts

Posted - 2009-03-16 : 16:40:34
To be more specific, I have 10 years worth of monthly databases. Each of these databases has the clients name, acct number and fee. No date columns or anything that I could order by that could link it to that particular database. Is there any way I produce this query so that I could know which quarterly database the fee would be linked to?
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-03-16 : 16:43:02
unless your tables have columns holding such info that you can use to order by on, there is nothing really you could rely on. You could do a SELECT* FROM and hope... however the order of results can be different for each execution.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -