[英]select fields from table where id not in another table in mysql [not working]
I'm trying to fetch data from a table and that id is not in another table. 我正在尝试从一个表中获取数据,并且该ID不在另一个表中。 I referenced some code example to solve this but it didn't still work.
我引用了一些代码示例来解决此问题,但仍然无法正常工作。 I tried two style for this.
我为此尝试了两种样式。 My tried sql code is as below and please help me.
我尝试过的sql代码如下,请帮助我。 Thank.
谢谢。
Style 1 样式1
SELECT *
FROM quotation q
WHERE q.quotationId NOT IN (SELECT ip.quotation_id FROM invest_project ip)
Style 2 风格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)
When you specify condition to not display null value data so try this 当您指定不显示空值数据的条件时,请尝试此操作
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)
This Work For Me 这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.