I want to get values of few columns of 'table1' if value of 'test' column of table1 is 0 else do left join with 'table2' and select few columns of 'table2' in sql?
Both table have different number of columns with different names.
SELECT t1.join_column,
t1.anycase_column,
CASE WHEN t2.join_column IS NULL
THEN t1.case_column
ELSE t2.case_column
END case_column
FROM table1 t1
LEFT JOIN table2 t2 ON t1.join_column = t2.join_column
AND t1.check_column != 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.