0

I want to delete three rows, from three separate tables. Here is my query, but it doesnt seem to work.

CREATE PROCEDURE `DB`.`deleteArticle` (IN x INT)
BEGIN

DELETE FROM articles
where article_id=x;

DELETE FROM AUTHORS
where submission_id = select submission_id from article_files where article_id=X;

DELETE FROM article_files
where article_id=X;

END
4
  • 4
    "it doesnt seem to work" what doesnt work ? errors ? what did you expect it to delete ? care to show some data from your table ? Commented Apr 10, 2012 at 13:23
  • You have a typo in the last block (DLETE should be DELETE)\ Commented Apr 10, 2012 at 13:25
  • @dragon112 sorry it was a type while typing the query. Commented Apr 10, 2012 at 13:26
  • Do you have any foreign key constraints in place? Eg I'd expect you need to delete from article_files before articles (or cascade delete from parent to child) Commented Apr 10, 2012 at 13:28

1 Answer 1

2

try this one

CREATE PROCEDURE `DB`.`deleteArticle` (IN x INT)
BEGIN

DELETE FROM articles
WHERE article_id=x;

DELETE FROM AUTHORS
WHERE submission_id IN (SELECT submission_id FROM article_files WHERE article_id=X);

DELETE FROM article_files
WHERE article_id=X;

END
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.