2)直接將查詢結果導入臨時表
CREATE TEMPORARY TABLE tmp_table SELECT * FROM table_name
create TABLE `tmp_table222222` select * from `xjy_term_relationships`,`xjy_posts` where `xjy_term_relationships`.`object_id`=`xjy_posts`.`ID`;
查ID字段有相同值,
SELECT * , COUNT( `ID` ) AS num
FROM `tmp_table222222`
GROUP BY `ID`
select * from `tmp_table222222`
where `id` in (select `id` from `tmp_table222222` group by `id` having count(`id`) > 1)
select `id`,`cid` from `tmp_table222222`
where `id` in (select `id` from `tmp_table222222` group by `id` having count(`id`) > 1)
SELECT `id` , `cid`
FROM `tmp_table222222`
WHERE `id`
IN (
SELECT `id`
FROM `tmp_table222222`
GROUP BY `id`
HAVING COUNT( `id` ) >1
)
ORDER BY `id`
多個delete語句一起執行。