I’m trying to make the following code smaller. Is this possible?
select a.* from table1 a WHERE a."cola1" = 'valuea1' UNION ALL select a.* from tablea1 a inner join tablea2 b on a."cola2" = b."colb2" WHERE a."cola1" = 'valuea2' and b."colb3" = 'valueb3'
In effect I’m looking for records from table1 for value1 or value2, but for records matching value2 I want to apply 1 extra condition which involves a join to a 2nd table
Can this be done without a UNION clause?
A skeleton or what I’m trying to code is below….but it’s not working naturally.
select a.* from table1 a inner join table2 b on a."cola1" = b."COLb1" WHERE a."cola2" IN ('valuea1','valuea2') and CASE WHEN a."cola2" = 'valuea2' THEN b."colb1" = 'valueb3' ELSE 1=1 END CASE