[英]Fetching unique rows from one table that columns reference has not in another table
I've two table first Name orders
我有两个表,第一个名字orders
2nd named printing
第二次命名printing
orders
table structure like this orders
表结构是这样的
id job_code job_name qty
1 597 xyz 1000
2 598 lmn 2500
3 599 oqr 20000
4 600 odc 15000
and printing
table structure like this 和这样printing
表结构
id job_code dispatch qty
1 598 yes 1800
2 600 yes 1456
i want to select all job.code
From orders
which is not in printing
table 我想从不在printing
表中的orders
选择所有job.code
I tried myself with this query. 我尝试使用此查询。
SELECT DISTINCT orders.job_code, orders.job_name, orders.qty FROM orders
INNER JOIN printing
ON orders.job_code <> printing.job_code ORDER BY orders.job_code DESC LIMIT 10;
OR 要么
SELECT DISTINCT orders.job_code, orders.job_name, orders.qty FROM orders
INNER JOIN printing
ON orders.job_code NOT IN (printing.job_code) ORDER BY orders.job_code DESC
LIMIT 10;
but it'll return all jobs which held on orders
and printing
tables 但是它将返回orders
和printing
表上保留的所有作业
select job_code from orders
where job_cobe not in (select job_code from printing)
You can use this query. 您可以使用此查询。
SELECT
DISTINCT orders.job_code, orders.job_name, orders.qty
FROM
orders
WHERE
orders.job_code
NOT IN
(SELECT printing.job_code FROM printing)
ORDER BY
orders.job_code DESC
LIMIT 10
use the query like this 使用这样的查询
SELECT job_code FROM `orders` left join printingorders on orders.job_code not in ( select job_code from printingorders)
This will give you the result. 这将为您提供结果。 I tried in my Phpmyadmin. 我在Phpmyadmin中尝试过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.