I 开发者_Go百科have many rows in Sale, and one Row in SalesProcessed.
SELECT * FROM Sale
INNER JOIN SalesProcessed
ON Sale.id<>SalesProcessed.id
LIMIT 0,30
This code returns same row which id is in SalesProcessed. Why?
Actually I need Sale rows which ID's doesn't exist in SalesProcessed.
SELECT *
FROM Sale
LEFT JOIN SalesProcessed
ON Sale.id = SalesProcessed.id
WHERE SalesProcessed.id IS NULL
LIMIT 0,30
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 query with explain for getting the best result
If you want non-existing rows, that's the wrong query:
SELECT *
FROM Sale
LEFT JOIN SalesProcessed
ON Sale.ID = SalesProcessed.id
WHERE SalesProcessed.id IS NULL;
精彩评论