I have a table with orders (for each order (transaction_id) there are client_id and item_id and quantity) I need to find completely identical orders for a set of goods and their quantity in the order
CREATE TABLE IF NOT EXISTS orders (client_id varchar(10),
item_id varchar(10), quantity int, transaction_id varchar(10));
INSERT INTO orders values
('CL1111','111',1, '1001'),
('CL1111','222',2,'1001'),
('CL1111','333',1,'1001'),
('CL2222','111',2,'1002'),
('CL2222','222',1,'1002'),
('CL2222','333',1,'1002'),
('CL3333','111',1,'1003'),
('CL3333','222',2,'1003'),
('CL3333','333',1,'1003'),
('CL3333','444',1,'1003'),
('CL4444','111',1,'1004'),
('CL4444','222',2,'1004'),
('CL4444','333',1,'1004'),
('CL5555','111',1,'1005'),
('CL5555','222',2,'1005'),
('CL6666','111',1,'1006'),
('CL6666','222',2,'1006'),
('CL6666','333',1,'1007')
client_id | item_id | quantity | transaction_id |
---|---|---|---|
CL1111 | 111 | 1 | 1001 |
CL1111 | 222 | 2 | 1001 |
CL1111 | 333 | 1 | 1001 |
CL2222 | 111 | 2 | 1002 |
CL2222 | 222 | 1 | 1002 |
CL2222 | 333 | 1 | 1002 |
CL3333 | 111 | 1 | 1003 |
CL3333 | 222 | 2 | 1003 |
CL3333 | 333 | 1 | 1003 |
CL3333 | 444 | 1 | 1003 |
CL4444 | 111 | 1 | 1004 |
CL4444 | 222 | 2 | 1004 |
CL4444 | 333 | 1 | 1004 |
CL5555 | 111 | 1 | 1005 |
CL5555 | 222 | 2 | 1005 |
CL6666 | 111 | 1 | 1006 |
CL6666 | 222 | 2 | 1006 |
CL6666 | 333 | 1 | 1007 |
Identical orders here are: (1001 and 1004), (1005 and 1006) And now I don't know, how to leave orders, which completely identical on item_id, quantity and set of items.