简体   繁体   English

从表中选择字段,其中id不在mysql的另一个表中[不起作用]

[英]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.

相关问题 MySql:从另一个表插入表SELECT中,其中first_table ID = another_table.id - MySql: insert into table SELECT from another table where first_table ID =another_table.id MySQL - SELECT 全部来自 TABLE_1,其中 TABLE_2 的两个字段中不存在 id - MySQL - SELECT all from TABLE_1 where id does not exist in two fields of TABLE_2 mysql查询-仅从另一个表中选择id = id,而该表中的字段=值 - mysql query - only select where id = id from another table and a field in that table = a value 从一个表中选择count(id),其中另一个表中存在该ID - Select count(id) from one table where that id is present in another table MYSQL 从一个表中选择所有字段,其中另一个ID为ID的表中的字段等于一个字符串 - Select all fields from a table where a field in another table with an ID is equal to a string MySQL SELECT * FROM表WHERE ID IN(子查询) - MySQL SELECT * FROM table WHERE id IN (subquery) 从ID不在另一个表中选择 - Select from table where id is not in another 从存在ID(从另一表)的一个表中选择 - Select from one table where id (from another table) exists MYSQL:来自table1的SELECT 1,其中Id = 1 vs SELECT EXISTS(来自table1的SELECT 1,其中Id = 1) - MYSQL: SELECT 1 from table1 where Id = 1 vs SELECT EXISTS(SELECT 1 from table1 where Id = 1) 从mysql中的另一个表中选择表并按值替换列字段 - select table and replace column fields by value from another table in mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM