Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Anyone explain why NULL is used in this query?

Tags:

sql

Also what will be the scenarios where this query is used

select * from TableA where exists  
    (select null from TableB where TableB.Col1=TableA.Col1)
like image 836
Rishabh Ohri Avatar asked Nov 30 '22 06:11

Rishabh Ohri


1 Answers

As the query is in an EXISTS then you can return anything. It is not even evaluated.

In fact, you can replace the null with (1/0) and it will not even produce a divide by zero error.

like image 158
Robin Day Avatar answered Dec 28 '22 06:12

Robin Day