简体   繁体   中英

Query 2 tables with left join that id dont exist in 3rd table

I got

table1    table2       table3

id         id           id
name       table1id     customerid
           table3id

How can i fetch the table1.name joining table2 where customerid = someid and table3id not exist in table2

    SELECT
       t1.id
       t1.name
    FROM
       Table1 t1
       LEFT JOIN Table2 t2
       on t1.id = t2.table1id
       LEFT JOIN Table3 t3
       on t2.table3id = t3.id
       AND t3.customerid = 93
    WHERE
       t3.id IS NULL
SELECT table1.name
INNER JOIN table2 ON table1.id = table2.table1id
WHERE table2.id NOT IN (SELECT id FROM table3)

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