Let's say I have two Oracle SQL tables for my invoices. INV_HEAD for adress, date, ... Then I have INV_POS for every position of the invoice.
INV_HEAD
--------
id
date
adr_id
total
INV_POS
---------
id
he_id
pos
art_id
quantity
price
I can list all the invoices with
SELECT he.id, he.date, po.art_id, po.quantity, po.price
FROM INV_HEAD he
JOIN INV_POS po on po.he_id = he.id
Now I want to find invoices with the same positions, not necessarily in the same order. How can I do this?
As a result I only need the INV_HEAD.id of all invoices with the same positions.
Here is same sample data:
id | he_id | pos | art_id | quantity | price
1 | 1 | 1 | 1000 | 5 | 100.00
2 | 1 | 2 | 2000 | 10 | 5000.00
3 | 2 | 1 | 2500 | 2 | 1250.00
4 | 3 | 1 | 2000 | 10 | 5000.00
5 | 3 | 2 | 1000 | 5 | 100.00
Invoice with he_id 1 and 3 have the same positions.
JOIN
them.