简体   繁体   中英

SQL - LEFT JOIN with Condition

SELECT *
FROM "Table 1" T1
LEFT JOIN "Table 2" T2 ON T1.ID = T2.ID
WHERE T2."Status" <> 'Void'

SQL: MYSQL

Hi all,

Above is my attempt so far, but it's not filtering the Void columns.

I need all the columns in Table 1 to remain, except if the "Status" column in Table 2 contains 'Void'.

Thanks,

You can try the following solution to see if it works.
Here I put filtering Table 2's status on the joint statement

SELECT *
FROM `Table 1` T1
LEFT JOIN `Table 2` T2
ON T1.ID = T2.ID AND T2.`Status` <> 'Void'

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM