首页 > 数据库技术 > 详细

MYSQL多表联合 创建成一个表

时间:2015-03-23 19:44:36      阅读:211      评论:0      收藏:0      [点我收藏+]

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语句一起执行。




MYSQL多表联合 创建成一个表

原文:http://anbaojia.blog.51cto.com/9494280/1623495

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!