我有以下查询我一直在使用,它足以显示我想在phpMyAdmin中删除的记录:
SELECT zen_customers_basket.*
FROM zen_customers_basket, zen_products
WHERE zen_customers_basket.products_id = zen_products.products_id
AND zen_products.products_availability = 'out of stock'
然后我检查所有的记录,然后删除它们。这是相当快速和无痛的,但我需要一个查询,将自动删除这些记录,这样我就可以自动化它与其他一些查询,计划每小时运行一次。任何和所有的帮助将不胜感激。我知道如何删除记录,但我不确定这里的正确语法,因为我从两个不同的表中选择的东西,我不想搞砸任何东西。
DELETE zen_customers_basket
FROM zen_customers_basket, zen_products
WHERE zen_customers_basket.products_id = zen_products.products_id
AND zen_products.products_availability = 'out of stock'
DELETE FROM Table WHERE EXISTS (SELECT zen_customers_basket.*
FROM zen_customers_basket, zen_products
WHERE zen_customers_basket.products_id = zen_products.products_id
AND zen_products.products_availability = 'out of stock')
https://stackoverflow.com/questions/8019957/delete-from-where-in 根据您的查询使用相同的条件删除。不确定按小时删除。请澄清。
DELETE FROM zen_customers_basket
INNER JOIN zen_products
ON zen_customers_basket.products_id = zen_products.products_id
WHERE zen_products.products_availability = 'out of stock'
参考:T-SQL: select rows to delete through joins