Search code examples
sqlsubquerycorrelated-subquery

Run a query based on output of another query


I have 3 queries based on first result i have to execute the 2 or 3rd query

If the output is 2 i have to eexute 2nd query

If the op is 3 then 3rd query

pls help


Solution

  • SELECT   XX,  
         CASE 
         WHEN Y =  1 THEN (Select X from table2 where xx= )
         WHEN Y = 2 THEN  (Select X from table3 where xx=)
      END 
       FROM table1
    

    Hope this answers your question