1

I have to find sku's (identifier) that are not listed in our catalog. Querys is simple

SELECT sku 
  FROM stock 
 WHERE sku NOT IN (SELECT sku FROM catalog) 

but there might be also missing sku's in table sale

SELECT DISTINCT sku 
  FROM sale 
 WHERE sku NOT IN (SELECT sku FROM catalog) 

I would like to get a single result from mysql, will all missing skus. To connect these two querys with Union will not work here. Thank you & Best Regards

ABSimon
  • 651
  • 1
  • 6
  • 18

1 Answers1

1

You could try using UNION

SELECT sku 
FROM stock 
WHERE sku NOT IN (SELECT sku FROM catalog) 

union 

SELECT sku 
FROM sale 
WHERE sku NOT IN (SELECT sku FROM catalog) 

for obtain the distink SKU from both the queries

or

select  sku  
from  (
  SELECT sku FROM stock 
  union   
  SELECT  sku  FROM sale 
) t
where sku NOT IN (SELECT sku FROM catalog) 

anyway the first should be more performant

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • 1
    just make sure that we guaranteed that `sku` returned from `catalog` won't be NULL; the NOT IN condition won't ever be satisfied if the subquery returns a NULL value – spencer7593 Jun 19 '19 at 20:02
  • @spencer7593 thank you for the hint. fortunately sku cant be null in my case – ABSimon Jun 24 '19 at 13:19