Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择不在其他表中的值_Mysql_Sql - Fatal编程技术网

Mysql 选择不在其他表中的值

Mysql 选择不在其他表中的值,mysql,sql,Mysql,Sql,假设我有两张桌子 Table client ID - primary key ( 1,2,3,4,5,6) Table Orders OrderID - primary key ClientID (1,2,4,5) 我需要获取客户端3和6的表CLIENT的行(它们没有订单/不在订单表中)这是基本查询。试试你自己 select * from client where id not in (select ClientID from orders) 好吧,但到目前为止你试过什么?您可

假设我有两张桌子

Table client

ID - primary key ( 1,2,3,4,5,6)




Table Orders

OrderID - primary key

ClientID (1,2,4,5)

我需要获取客户端3和6的表CLIENT的行(它们没有订单/不在订单表中)

这是基本查询。试试你自己

select * from client where id not in (select ClientID from orders)

好吧,但到目前为止你试过什么?您可以编写您的基本SQL代码吗?not in()在表2中的可空性很差,但您可以在右边的表中使用null进行左连接。我的大多数评论都是晦涩难懂的