我想删除此select语句选择的所有结果,我该怎么做?
SELECT
*
FROM
db.wp_term_taxonomy A,
db.wp_terms B
WHERE
A.taxonomy = 'post_tag' AND B.term_id = A.term_id
答案 0 :(得分:2)
DELETE B.* FROM db.wp_terms B
INNER JOIN db.wp_term_taxonomy A ON B.term_id = A.term_id
WHERE (A.taxonomy = 'post_tag');
DELETE FROM db.wp_term_taxonomy
WHERE taxonomy = 'post_tag'
答案 1 :(得分:1)
DELETE
FROM
db.wp_term_taxonomy A,
db.wp_terms B
WHERE
A.taxonomy = 'post_tag' AND B.term_id = A.term_id
答案 2 :(得分:1)
DROP TABLE IF EXISTS wp_term_taxonomy;
CREATE TABLE wp_term_taxonomy(term_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, taxonomy VARCHAR(12) NOT NULL UNIQUE);
DROP TABLE IF EXISTS wp_terms;
CREATE TABLE wp_terms(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, term_id INT NOT NULL);
INSERT INTO wp_term_taxonomy VALUES (1,'post_box'),(2,'post_bag');
INSERT INTO wp_terms VALUES (1,1),(2,1),(3,2),(4,2);
DELETE a,b FROM wp_term_taxonomy a JOIN wp_terms b ON b.term_id = a.term_id WHERE a.taxonomy = 'post_bag';
SELECT * FROM wp_term_taxonomy;
+---------+----------+
| term_id | taxonomy |
+---------+----------+
| 1 | post_box |
+---------+----------+
SELECT * FROM wp_terms;
+----+---------+
| id | term_id |
+----+---------+
| 1 | 1 |
| 2 | 1 |
+----+---------+
作为替代方案,请参阅InnoDB表的CASCADE选项