标签:
create table java (name varchar(255));
insert into java values (‘java1‘),(‘java2‘),(‘blue‘);
create table mysql (name varchar(255));
insert into mysql values (‘mysql1‘),(‘mysql2‘),(‘blue‘);
1.join 查询 内联查询 查两个表的内才联系相同的值
select * from java join mysql as my on my.name = java.name;
+------+------+
| name | name |
+------+------+
| blue | blue |
+------+------+
1 row in set (0.00 sec)查询结果
2.left join 外联查询 已左表为主表 左表的信息全部会全部查出来 右表的信息只有相关联的才能查出来 剩下的查询结果为null 效率慢一点
select * from java left join mysql as my on java.name=my.name;
+-------+------+
| name | name |
+-------+------+
| java1 | NULL |
| java2 | NULL |
| blue | blue |
+-------+------+
3 rows in set (0.00 sec) 查询结果
3.rignt join 正好与left join 相反
标签:
原文地址:http://www.cnblogs.com/huiting/p/4537666.html