Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does adding count(*) to a select statement force a row to exist in a subquery?

On Oracle 9i, why does the following produce the result 'abc'

select 'abc ' || (select txt from 
     (select 'xyz' as txt from dual where 1=2)) 
from dual

while this produces 'abc xyz':

select 'abc ' || (select txt from 
     (select count(*), 'xyz' as txt from dual where 1=2)) 
from dual

Why does adding count(*) to the subquery result in different behavior? Should the predicate where 1=2 preclude any results in the subquery?

like image 893
LBushkin Avatar asked Mar 10 '26 15:03

LBushkin


1 Answers

select count(*) from dual where 1=2

returns 0. That is, a row with the value zero.

like image 115
Carl Manaster Avatar answered Mar 12 '26 05:03

Carl Manaster



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!