https://stackoverflow.com/questions/2686254/how-to-select-all-records-from-one-table-that-do-not-exist-in-another-table so it''s this: SELECT t1.name FROM table1 t1 LEFT JOIN table2 t2 ON t2.name = t1.name WHERE t2.name IS NULL
https://stackoverflow.com/questions/2686254/how-to-select-all-records-from-one-table-that-do-not-exist-in-another-table so it''s this: SELECT t1.name FROM table1 t1 LEFT JOIN table2 t2 ON t2.name = t1.name WHERE t2.name IS NULL fridec2 发表于 2023-04-14 18:09
https://stackoverflow.com/questions/2686254/how-to-select-all-records-from-one-table-that-do-not-exist-in-another-table so it''s this: SELECT t1.name FROM table1 t1 LEFT JOIN table2 t2 ON t2.name = t1.name WHERE t2.name IS NULL fridec2 发表于 2023-04-14 18:09
可以在这先试一下:找从没买过东西的 customer https://www.w3schools.com/sql/trysql.asp?filename=trysql_asc (1) SELECT t1.* FROM customers t1 LEFT JOIN orders t2 ON t2.customerid = t1.customerid WHERE t2.customerid IS NULL; (2) select * from orders where customerid = 6; (3) select * from orders where customerid = 7; 看着是对的 😄
key 这么几个,两个query 加excel 也行。
我问了,where 后面跟 table2.key is null,可是没结果
so it''s this:
SELECT t1.name FROM table1 t1 LEFT JOIN table2 t2 ON t2.name = t1.name WHERE t2.name IS NULL
我用的就是这个,可结果只出来一行
left join table2 或是用not in, 这个需要比较的column里没有null。
这个是正解 我一直用啊
https://www.w3schools.com/sql/trysql.asp?filename=trysql_asc
(1) SELECT t1.* FROM customers t1 LEFT JOIN orders t2 ON t2.customerid = t1.customerid WHERE t2.customerid IS NULL;
(2) select * from orders where customerid = 6;
(3) select * from orders where customerid = 7;
看着是对的 😄
所以你先要inner join test table A (500 records ) 是否和table B(400) 真有400个相同的记录,如果不是,A left join B return 1 record 当然可能。
select * from table a where a.id not in (select id from table b)
"Not In" will not work if there are nulls.
怎么调整的?能不能发上来让大家学习一下。