0

I'm trying to delete data from a table in MySQL, but before I execute the command I want to make sure that I am doing it right. I'm looking to delete all rows with a storeID > 5000000 and cannot match to any item in the deals table. Below is my query:

DELETE FROM stores s 
LEFT JOIN deals sd 
ON s.storeID = sd.store_ID 
WHERE storeID > 5000000 
AND sd.dealID IS NULL;

Will the above query only delete the rows in the stores table and not affect the deals table?

2
  • what happens when you try? Commented Feb 24, 2016 at 20:32
  • It's a production table, so I don't really want to try without being sure. Commented Feb 24, 2016 at 20:34

1 Answer 1

1

If you are concerned with the query deleting extra stuff from your production table I'd suggest spinning up a development instance and replicating the database schema. If possible take a full dump of the production database and import it into your development/test system. That way you can test your queries and know for certain their outcome.

If you you want a dump of the database or even just the databases schema you can use mysqldump to generate these.

I don't think your query will remove anything from the deals table, but I would recommend you check to be 100% certain. Is this not going to leave you with rows in the deals table that reference a storeid that isn't in the stores table?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.