MYSQL多表聯合 創建成一個表

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語句一起執行。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章