Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql - Insert between two rows?

Tags:

sql

insert

I wish to know how I can insert a row between the two rows of a table. I am using MS-SQL and SQL management studio.

Any help will be much appreciated.

like image 424
SEA Avatar asked Jan 23 '26 08:01

SEA


1 Answers

If you do just a

SELECT (columns) FROM dbo.MyTable

there is no guaranteed order in the output - it might look like it's ordered, but there's no guarantee for anything.

If you want to order by something, you need to explicitly specify that by adding an ORDER BY clause to your statement:

SELECT (cols) FROM dbo.MyTable ORDER BY FirstName

Therefore, you cannot "insert" a new row between two other rows - it will just show up wherever it belongs, based on the order you've defined

like image 83
marc_s Avatar answered Jan 25 '26 23:01

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!