风动破

导航

第四章 求交集--intersect运算

select * from staff
intersect
select * from staff_copy;
mysql不支持,需要通过自己实现
SELECT id,name,level from (  
    SELECT id ,name ,level from staff  
    UNION ALL  
    SELECT id ,name ,level  from staff_copy  
)a 
GROUP BY id,name,level
 HAVING count(*)>1  
 如果字段名称不一样的话需要
 SELECT c_id,name,level from (  
    SELECT id  as c_id,name ,level from staff  
    UNION ALL  
    SELECT id1 as c_id ,name ,level  from staff_copy  
)a   
GROUP BY c_id,name,level
 HAVING count(*)>1  

posted on 2015-04-27 17:07  风动破  阅读(90)  评论(0)    收藏  举报