- check new products in products_tmp that are not included in the products (get identifiers) (DONE)
This is straightforward ...
SELECT pt.*
FROM products_tmp pt
LEFT JOIN products p ON p.product_id = pt.product_id
WHERE p.product_id IS NULL;
- check old products in products that are not in product_tmp (get identifiers for subsequent removal) (DONE)
A always prefers to replace tables with execution RIGHT JOINS- personal preferences ...
SELECT p.*
FROM products p
LEFT JOIN products_tmp pt ON p.product_id = pt.product_id
WHERE pt.product_id IS NULL;
3. Check the differences from the rest. Both tables have a unique hash product identifier.
. , , ...
SELECT product_id, count(*) cnt
FROM (
SELECT p.product_id, p.field2, p.field3
FROM products p
UNION
SELECT pt.product_id, pt.field2, pt.field3
FROM products_tmp pt
) pd
GROUP BY product_id
HAVING cnt > 1;
UNION , , 2 , . , , , .