Our app has been using this query for a while now:
SELECT id
FROM invoice
WHERE id NOT IN
(SELECT invoice_id FROM invoice_transaction)
#437 rows returned
In a code review, this query was rewritten with a left outer join:
SELECT invoice.id
FROM invoice
LEFT OUTER JOIN invoice_transaction on invoice.id=invoice_transaction.invoice_id
#586 rows returned
The first query returns 437 rows and the second (supposedly identical) query returns 586 rows. Is this not a valid use of the left outer join?
What would be a better way to rewrite this query?
Thank you!
The following query should return the same results of the first query: