如何从此查询中删除结果?

时间:2012-06-07 15:11:05

标签: mysql

如何从数据库中删除此查询的结果? 请你帮帮我吗

SELECT v.type
FROM poll_answers
JOIN vote_types v ON poll_answers.vote_id = v.id
JOIN poll_questions q ON q.id = poll_answers.question_id
WHERE q.referendum_id =1

我试图逐个删除它,但是我有外键问题所以我想逐步删除

谢谢

1 个答案:

答案 0 :(得分:1)

试试这个:

delete poll_answerpoll_answer,v,q,
FROM poll_answers
JOIN vote_types v ON poll_answers.vote_id = v.id
JOIN poll_questions q ON q.id = poll_answers.question_id
WHERE q.referendum_id =1

修改

mysql> delete poll_answers,v,q
    -> FROM poll_answers
    -> JOIN vote_types v ON poll_answers.vote_id = v.id
    -> JOIN poll_questions q ON q.id = poll_answers.question_id
    -> WHERE q.referendum_id =1;
Query OK, 0 rows affected (0.00 sec)