您的位置:首页 > 数据库 > MySQL

mysql连接和联和

2015-11-04 00:00 591 查看
select * from tablenaem ,tablename2
where cid1 = cid2 and cname1 = 'songjian';
交叉连接
select * from tablename1 , tablename2 多条合并
或者select * from tablenaem1 cross join tablename2 效果一样的

内连接
逗号或者inner join 方式合并的
内连接存在where条件的
交叉连接不存在where条件

外连接
left join on
right join on
select * from user ;
select * from group;
select * from user_group;

select * from user u , group g , user_group ug
where u.userid = ug.userid and g.groupid = ug.groupid --内连接

select * from user u left join user_group ug on u.userid = ug.userid where ug.name is null ;--左连接, 左边必须存在,右边不一定存在
或者使用using
select * from user_group right group using (groupId)

自连接和联和
menu
id name parentid
select * from menu ;
select a.name as parentname , b.name as childname from
menu a , menu b
where a.id = b.parentid ;

联和
select * from tablename1 union select * from tablename2; 去重复
union all 不去重复
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: