I have two tables below. I am looking to find all the combinations of store
and newid
in sales2
which are not present in sales1
and combine them with sales1
.
I am looking for the end result to be:
store newid amount total
123 | 123 | 12.3 | 1
456 | 123 | 45.6 | 2
789 | adsf | 78.9 | 3
321 | 123f | NULL | NULL
789 | 1654 | NULL | NULL
Original Tables
CREATE TABLE sales1 (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
store VARCHAR(30) NOT NULL,
newid VARCHAR(30),
amount DOUBLE,
total INT
);
CREATE TABLE sales2 (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
store VARCHAR(30) NOT NULL,
newid VARCHAR(30),
amount DOUBLE
);
INSERT INTO sales1 (store, newid, amount, total) VALUES
('123','123', 12.3, 1),('456','123', 45.6, 2),('789','adsf', 78.9, 3);
INSERT INTO sales2 (store, newid, amount) VALUES
('123','123', Null),('456','123', Null),('321','123f', Null),('789','1654', Null);