-1

我想删除此 select 语句选择的所有结果,我该怎么做?

SELECT
    *
FROM
    db.wp_term_taxonomy A,
    db.wp_terms B
WHERE
    A.taxonomy = 'post_tag' AND B.term_id = A.term_id
4

3 回答 3

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'
于 2013-06-24T11:54:22.587 回答
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 选项

于 2013-06-24T12:01:24.133 回答
1
DELETE
FROM
db.wp_term_taxonomy A,
db.wp_terms B
WHERE
A.taxonomy = 'post_tag' AND B.term_id = A.term_id
于 2013-06-24T11:46:48.227 回答