0

I need to delete data from two tables at once. I have articles in one spreadsheet, and I have page permissions in the other spreadsheet that clearly specify who gets to the article and who doesn't. However, if I want to delete a given article, I am unable to put together the sql code to delete the permissions based on the url article. I tried this without any result

DELETE * FROM article_permission
JOIN article ON article.article_id = article_permission.article_id
WHERE article.url = 'kjebgkwb'

3 Answers 3

1
DELETE ap.*, a.* 
FROM article_permission ap
JOIN article a ON a.article_id = ap.article_id
WHERE a.url = 'kjebgkwb'
Sign up to request clarification or add additional context in comments.

Comments

0
delete t1.*, t2.* FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id WHERE t1.id = 'idnumber'

Or

You have to run two different delete query or You have to set foreign key on the other table so it will automatically delete records with this id.

Comments

0
DELETE p, a 
FROM article_permission p
JOIN article a ON a.article_id = p.article_id
WHERE a.url = 'kjebgkwb'

It is even easier if you set your table relation to ON DELETE CASCADE then you only need to delete from the article table and the DB does the rest for you.

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.