June 6, 2011 at 9:16 am
Hi
I was wondering if someone could help me with this.
I have a table called history and it contains about 70 columns, when i do a select * from history 198 rows are returned and the top row has the values below
co1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9 | col10 | col11 | col12
454 | 550 | 688 | 310 | 526 | 694 | 858 | 898 | 766 | 476 | 362 | 198
Now this is the weird part, when i use a select col1, colu2 etc from history the top values are completely different as shown below.
col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9 | col10 |col11 | col12
231 | 370 | 529 | 899 | 890 | 961 | 759 | 572 | 338 | 751 | 599 | 506
So when you compare the two queries the results are completely different surely this should not be the case.
Can anyone shed any light on the reason for the this
Thanks in advance
__________________________________________________________________________________
Steve J
Jnr Developer
BSc(Hon)
June 6, 2011 at 9:25 am
Ordering is not guaranteed when you do not specify order by clause. So if you have no order by clause, then the query optimizer is free to return rows in any order.
June 6, 2011 at 9:26 am
Do you have an ORDER BY?
If not, SQL makes absolutely no guarantees about the ordering that the data will be returned in. It'll be whatever order the rows are based on the query operators chosen.
If you need a specific order, specify ORDER BY. Otherwise the order can and will change.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 6, 2011 at 9:32 am
Thansk for your reply GilaMonster , skcadavre
To be honest i dont know where i didnt think of that lol, i'll try that now
__________________________________________________________________________________
Steve J
Jnr Developer
BSc(Hon)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply