SQL Puzzle – Unsolved CASE Expression

My earlier puzzle SQL Puzzle – SELECT ~ 1 : Guess the Answer received over 125 responses while I am writing this one. Lots of people have asked me to share another puzzle. Well, let us see a very simple puzzle of Unsolved CASE Expression.

SQL Puzzle - Unsolved CASE Expression UnsolvedCASEExpression-800x278

Unsolved CASE Expression

Without running the following command, guess the output of the SELECT statement:

SELECT
CASE
WHEN 1 <> 1 THEN 1
WHEN 2 <> 2 THEN 2
END 'Result'

As I really want you to run the query, I am not going to share the output here in this blog post. Once you run the puzzle, I would like you to comment on the reason for the query to return the result which it is returning.

Well, that’s it for today. Leave your answer in the comments section.

Let me know if you are interested to know more about this topic and I will write more blogs as well as create an SQL in Sixty Seconds video.

Here are my few recent videos and I would like to know what is your feedback about them.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

, ,
Previous Post
SQL Puzzle – SELECT ~ 1 : Guess the Answer

Related Posts

9 Comments. Leave new

  • Ok I guessed the answer correctly. If 1 does not = 1 then 1 / if 2 does not = 2 then 2. Both are false statements and there is no Else statement therefore no value so null is returned in the column named “Result”

    Reply
  • NULL because case conditions can’t evaluate to true

    Reply
  • Ketki Kulkarni
    May 20, 2021 3:36 pm

    NULL

    Reply
  • Mahesh Mahajan
    June 4, 2021 2:32 pm

    NULL as CASE Conditions are not returning TRUE

    Reply
  • Priti Kumari
    June 16, 2021 9:55 pm

    Null because none of the statements are true

    Reply
  • SANDYA RANI GATTUPALLI
    April 1, 2022 12:22 pm

    NULL as because none of the conditions are true

    Reply
  • Rhythm Luthra
    June 29, 2022 7:11 pm

    The following query will create a column and will display the column name as result if the when statement is true which is if 1 is not equal to 1 and 2 is also not equal to 2 in second statement only then in the result column first row will display as 1 and second row will display as 2.

    Reply
  • null because the query wasn’t close using the ;

    Reply
  • It wouldn’t run because there is no column from where the case statement would work on.
    There’s no column indicated after the Case statement or when given the condition.

    Reply

Leave a Reply