SQL How to add if else conditions in sql SQL How to add if else conditions in sql sql sql

SQL How to add if else conditions in sql


This should do the trick :

SELECT A.*, B.* FROM TABLE1 AINNER JOIN TABLE2 B ON A.MSISDN = B.MSISDNWHERE (UPPER(B.FIRSTNAME),UPPER(B.LASTNAME)) NOT IN ((UPPER(A.FIRSTNAME),UPPER(A.LASTNAME)),(UPPER(A.FIRSTNAME),UPPER(A.SECONDNAME)))

No need for IF , if this condition returns true, it means all your conditions are met, and either first_name is different or last_name is .


You probably want to use a CASE expression.

They look like this:

SELECT col1, col2, (case when (action = 2 and state = 0)  THEN      1  ELSE      0  END) as state from tbl1;


This will do it. Basically you just need exclude results where both, firstname and second/lastname are matching.

SELECT A.*, B.* FROM TABLE1 AINNER JOIN TABLE2 B ON A.MSISDN = B.MSISDNWHERE (NOT (A.FIRSTNAME = B.FIRSTNAME AND A.SECONDNAME = B.LASTNAME))AND (NOT (A.FIRSTNAME = B.FIRSTNAME AND A.LASTNAME = B.LASTNAME))