MySQL Internal join with not equal operator

I have many lines in sales and one line in SalesProcessed.

SELECT * FROM Sale INNER JOIN SalesProcessed ON Sale.id<>SalesProcessed.id LIMIT 0,30 

This code returns the same line as the identifier in SalesProcessed. Why?

Actually, I need sales lines whose identifier does not exist in SalesProcessed.

+4
source share
3 answers
 SELECT * FROM Sale LEFT JOIN SalesProcessed ON Sale.id = SalesProcessed.id WHERE SalesProcessed.id IS NULL LIMIT 0,30 
+10
source

Another approach

 SELECT * FROM Sale where Sale.id not in (select SalesProcessed.id from SalesProcessed) LIMIT 0,30 SELECT * FROM Sale where NOT EXISTS ( select SalesProcessed.id from SalesProcessed where Sale.id=SalesProcessed.id) LIMIT 0,30 

You should check each request with an explanation to get the best result.

+4
source

If you need non-existent strings, this is the wrong query:

 SELECT * FROM Sale LEFT JOIN SalesProcessed ON Sale.ID = SalesProcessed.id WHERE SalesProcessed.id IS NULL; 
+4
source

Source: https://habr.com/ru/post/1369240/


All Articles