Linked Questions

111 votes
3 answers
171k views

What is the default order of records for a SELECT statement in MySQL?

Suppose you have the following table and data: create table t ( k int, v int, index k(k) ) engine=memory; insert into t (k, v) values (10, 1), (10, 2), (10, 3); When ...
daisy's user avatar
  • 1,328
0 votes
3 answers
17k views

Is there a default SELECT order? [duplicate]

I need to clear up what I mean by order here. I am simply asking about what order the data is fetched in. If I simply SELECT * FROM table; in SQL Server without an ORDER BY clause, I find that the ...
Manngo's user avatar
  • 2,859
7 votes
4 answers
2k views

Does an IOT guarantee order in a select?

We need to add a priority column to a table that gets hit about 250 times a second, approx 170 selects, 125 inserts and 60 updates. The column will be a simple number(1). The priority does not matter ...
Ben's user avatar
  • 462
12 votes
1 answer
4k views

How does SQL Server order results when joins are used?

How does SQL Server figure out the order of the records in the result set of query execution? I am trying to make heads or tails of it but find myself scratching my head. When I change the fields I ...
kacalapy's user avatar
  • 2,052
8 votes
1 answer
6k views

Storage order vs Result order

This is a spin-off question from Sort order specified in primary key, yet sorting is executed on SELECT. @Catcall says this on the subject of storage order (clustered index) and the output order A ...
m__'s user avatar
  • 529
4 votes
2 answers
16k views

Using TOP in INSERT INTO statement

I am reading a tutorial about TOP keyword in T-SQL. But I don't really understand the examples given in the tutorial. Example 1: INSERT TOP n INTO table_name1 (Col1, Col2) SELECT Col3, Col4 FROM ...
user avatar
2 votes
1 answer
1k views

What is the order when SELECT-ing unordered set from an ordered SELECT?

What does the SQL standard and its mainstream DB implementations (SQL Server, Oracle, DB2, PostgreSQL, Firebird, MySQL, etc.) say about the final order in the following general case: SELECT * FROM (...
aoven's user avatar
  • 169
2 votes
1 answer
908 views

weird sql server behavior when inserting and selecting

Today after one of the drives on our sql server ran out of space. The drive contained eventracker logs, so I didn't think it was a big deal, but then I noticed when I insert a record into a database, ...
Max Marchevsky's user avatar
-1 votes
1 answer
832 views

Clustered Index and Sorting [duplicate]

select * from [table_a]; A clustered index sorts the table based on whatever column(s) you choose. That being said, if I have a clustered index on [column_a], [column_b], and [column_c] and run the ...
Chicken Sandwich No Pickles's user avatar
1 vote
1 answer
429 views

Logic of Assigning values to variables in Scalar-valued Functions

I am currently working on updating old scalar valued functions with the hope of making them more efficient or changing them into Inline TVFs. While troubleshooting my rewrites I came across some ...
Thomas D.'s user avatar
  • 113
0 votes
1 answer
200 views

Join reorders results [duplicate]

Is there any particular reason why adding an additional join to an ordered table would reorder the result set? Using a left join on the existing result set table-valued function is similar to below (...
Drew's user avatar
  • 318