select 来自 table 的字段,其中 ID 不在 mysql 中的另一个 table [不工作]

select fields from table where id not in another table in mysql [not working]

我正在尝试从 table 中获取数据,但该 ID 不在另一个 table 中。我参考了一些代码示例来解决这个问题,但它仍然没有用。我为此尝试了两种风格。我试过的 sql 代码如下,请帮助我。谢谢

样式 1

SELECT *
FROM quotation q
WHERE q.quotationId NOT IN (SELECT ip.quotation_id FROM invest_project ip)

样式 2

SELECT *
FROM quotation q
LEFT JOIN invest_project ip
ON q.quotationId = ip.quotation_id
WHERE q.quotationId IS NULL

尝试不使用别名...

SELECT * FROM quotation WHERE quotation.quotationId NOT IN (SELECT quotation_id FROM invest_project)

当您指定不显示空值数据的条件时 试试这个

SELECT *
FROM quotation q
WHERE q.quotationId NOT IN (SELECT ip.quotation_id FROM invest_project ip) or q.quotationId is null
Select *  
from [Table1] AS T1  
where not exists( select * from [Table2] AS T2 where T1.ID = T2.ID)  

这对我有用