Originally Posted by
DivaVocals
I'm using this script to locate records in my SBA table where the product no longer exists..
Code:
SELECT *
FROM zen_products_with_attributes_stock
LEFT OUTER JOIN zen_products
ON (zen_products.products_id = zen_products_with_attributes_stock.products_id)
WHERE zen_products.products_id IS NULL
I have validated that these products no longer exist.. so I'm confident that these records can be deleted from the SBA table.. I need to know how to delete these records.. Kinda stumped on how to do this.. Hoping smarter brains than mine can help here..
Or using your specific results of your query.
Code:
Delete from products_with_attributes_stock pwas
Where pwas.products_id in (
SELECT UNIQUE pwas1.products_id
FROM products_with_attributes_stock pwas1
LEFT OUTER JOIN products p
ON (p.products_id = pwas1.products_id)
WHERE p.products_id IS NULL
)
Though I think this later version is a bit more consuming than the earlier... Ideally left inner joins should be performed rather than outer joins... The first version does that (and ought to provide you the same results as what you posted), this second uses your outer join method. I threw in the unique statement just to be sure, probably doesn't need it.
Bookmarks