Strange Adventure with SQL Server
What does The followin query return IF orders table does NOT have a transfer_id column?
select transfer_id from orders
if you answered a runtime error - you were correct! read on...
What does the following query give you if transfers has transfer_id columns BUT orders table does NOT have any transfer_id column?
select * from transfers
where transfer_id in
(select transfer_id from orders)
if you answered a runtime error - you're WRONG! SQL Server simply returns ENTIRE Transfers table to you without ANY errors!
Any reasons behind this strange behavior? None comes to my mind!!!
but,
select * from transfers
where transfer_id in
(select orders.transfer_id from orders)
DOES return a runtime error and is a MUCH professional and better way of writting Sql Qruery!
select transfer_id from orders
if you answered a runtime error - you were correct! read on...
What does the following query give you if transfers has transfer_id columns BUT orders table does NOT have any transfer_id column?
select * from transfers
where transfer_id in
(select transfer_id from orders)
if you answered a runtime error - you're WRONG! SQL Server simply returns ENTIRE Transfers table to you without ANY errors!
Any reasons behind this strange behavior? None comes to my mind!!!
but,
select * from transfers
where transfer_id in
(select orders.transfer_id from orders)
DOES return a runtime error and is a MUCH professional and better way of writting Sql Qruery!
0 Comments:
Post a Comment
<< Home