SQL Query Output | EXL interview question
Question
select case when null=null then ‘Amit’ else ‘Rahul’ end from dual
in progress
2
SQL
55 years
14 Answers
2063 views
Grand Master 1
Answers ( 14 )
In SQL, Result of null=null is unknown and it can’t be true because two null values can never be same.
So Answer will be:
Rahul
No 2 nulls are ever the same. Thus the condition “null=null” will never be met.
Output: Rahul
The Null value has a memory reference.2 Null values cannot have same memory
reference.
so output will be ‘Rahul’.
Null=Null, condition will never satisfy. The output will always ‘Rahul’
Sorry it a private answer.
We cannot match NULL values. To the given question the output is RAHUL
Rahul is the output
As NULL=NULL, this condition will never satisfy
Output: Rahul
Reason: null=null condition will never hold true.
This question is basically asking ‘Does one unknown equal another unknown?’ (NULL = NULL)
That question is something no one can answer so it defaults to true or unknown depending on your ansi_nulls setting. if you have ANSI_NULLS off, this will evaluate to true otherwise it will be unknown.
The answer is Rahul based on the assumption that ANSI_NULLS is ON.
https://docs.microsoft.com/en-us/sql/t-sql/statements/set-ansi-nulls-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15
The null has a memory reference. So, one null value cannot be equal to another null value.
See the below result:
select
case when null=null
then ‘Amit’
else ‘Rahul’
end
as Result
from dual;
================================================
Result=Rahul
Output =Rahul
As null =null can’t be true
x = x only holds true when x is a known value. NULL is a textual representation of an unknown value. Two unknown values can’t conclusively state anything about their equality.
Therefore, NULL = NULL results in either “Fasle” or “NULL”.
So, the answer is Rahul.
NULL = NULL condition can’t hold true.
So, the answer is returned by the else clause.
Hence, answer is ‘Rahul’.
Two null values can never be the same therefore the output will be Rahul.