sql-select-null-usage.md
select null example
I saw a sql code snippet as this:
1 | select * |
why we use select null
here, I tried with select *
, the result is the same.
usage explaination
the above sql do one thing : find the row which exists in view v
but not in view e
. but why we use select null
here?
the main reason is that we don’t need really select any column from v
, all we want is what the where
clause does, we comparev.empno = e.empno
etc. After comparision, we exclude v’s row which is in ‘e’ also. you can do select 1
instead here, they have the same performance. but if you use select *
, it would bring the data of view e
although we don’t display e's
column in our
result. Then the performance would be worse than select null
or select 1
here is a post select null which has in-depth explaination.