0

I have the following query I have been using and it works well enough for displaying the records I want to delete in 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'

I then check all the records and then delete them. It's fairly quick and painless, but I need a query that will automatically delete these records so I can automate it with some other queries that are scheduled to run once per hour. Any and all help would be appreciated. I know how to delete records but I'm not sure of the proper syntax here since I'm selecting things from two different tables and I don't want to screw anything up.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1678042
  • 45
  • 1
  • 2
  • 6

3 Answers3

0
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'
Greg Oks
  • 2,700
  • 4
  • 35
  • 41
0
    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

Community
  • 1
  • 1
CodeMonkey
  • 1,087
  • 2
  • 15
  • 24
0

Delete using same conditions as per your query. Not sure the deleting based on hour. Please clarify.

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'

Reference: T-SQL: Selecting rows to delete via joins

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91