Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Nested CASE statement in the WHERE clause

I am trying to use NESTED CASE statement(BOLD Below) where, based on first CASE statment, I need to verify inner where clause, else other inner where clause. Is below right approach when using nested CASE When statements?

SELECT COUNT(*)
FROM   <list of table>
WHERE  <list of conditions > 
AND    CASE  WHEN cond1 <> 1 or cond2 <>2 or cond3 <> 3
             THEN 
                WHEN ( col1,col2,col3) NOT IN (SELECT col1,col2,col3
                                               FROM   table 1,table 2
                                               WHERE  <condition1> )
                ELSE ( col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
                                                    FROM   table 1,table 2
                                                    WHERE  <condition2> )
             END
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use AND and OR:

SELECT COUNT(*)
FROM   <list of table>
WHERE  <list of conditions > 
AND    (  (   ( cond1 <> 1 OR cond2 <> 2 OR cond3 <> 3 )
          AND (col1,col2,col3) NOT IN (SELECT col1,col2,col3
                                       FROM   table1
                                              INNER JOIN table2
                                              ON (<condition>)
                                       WHERE  <condition1>)
          )
       OR (   NOT ( cond1 <> 1 OR cond2 <> 2 OR cond3 <> 3 )
          AND (col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
                                            FROM   table1
                                                   INNER JOIN table2
                                                   ON (<condition2>)
                                            WHERE  <condition2> )
          )
       )

Notes: Do not use legacy comma joins, use the modern ANSI join syntax.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!