选择未从SELECT中选择的记录

时间:2017-01-03 12:52:37

标签: sqlite select

我从表LABELS中选择所有记录,我和INNER JOIN也使用SELECT来获取其他表中存在的其他一些数据。所以我的问题是:

SELECT LABELS.oldLabel, LABELS.label, LABELS.version, LABELS.description, LABELS.type, LABELS.cutter, LABELS.valid, LABELS.dateCreated, LABELS.dateModified, CUSTOMERS.name AS customer, CUSTOMERS.id, SUPPLIERS.name AS supplier FROM LABELS 
INNER JOIN CUSTOMERS 
ON LABELS.customer = CUSTOMERS.id 
INNER JOIN SUPPLIERS 
ON LABELS.supplier = SUPPLIERS.id 
GROUP BY LABELS.oldLabel, LABELS.label, LABELS.version, LABELS.description, LABELS.type, LABELS.cutter, LABELS.customer, LABELS.valid, CUSTOMERS.name , CUSTOMERS.id, SUPPLIERS.name

表格LABELS中的记录大小为3169。但是,上面的语句返回308980个记录丢失了。

有没有办法获取所有记录,除了上面的选择,以便查看这些记录是什么,并弄清楚为什么没有选择它们?

我试过了:

Select * FROM labels where not exists( the_above_select)

但我没有得到任何记录......

1 个答案:

答案 0 :(得分:1)

SELECT * from Labels WHERE label NOT IN 
(SELECT  label from Labels INNER JOIN CUSTOMERS
   ON LABELS.customer = CUSTOMERS.id 
   INNER JOIN SUPPLIERS 
   ON LABELS.supplier = SUPPLIERS.id)