跟燕十八学习PHP-第二十七天-左右内连接的区别
/**
燕十八 公益PHP培训
课堂地址:YY频道88354001
学习社区:www.zixue.it
**/
mysql> create table boy (
-> bname varchar(20),
-> other char(1)
-> )engine myisam charset utf8;
Query OK, 0 rows affected (0.23 sec)
mysql>
mysql> insert into boy
-> values
-> ('屌丝','A'),
-> ('李四','B'),
-> ('王五','C'),
-> ('高富帅','D'),
-> ('郑七','E');
Query OK, 5 rows affected (0.02 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql>
mysql> create table girl (
-> gname varchar(20),
-> other char(1)
-> )engine myisam charset utf8;
Query OK, 0 rows affected (0.16 sec)
mysql>
mysql> insert into girl
-> values
-> ('空姐','B'),
-> ('大S','C'),
-> ('阿娇','D'),
-> ('张柏芝','D'),
-> ('林黛玉','E'),
-> ('宝钗','F');
Query OK, 6 rows affected (0.03 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> select * from boy;
+--------+-------+
| bname | other |
+--------+-------+
| 屌丝 | A |
| 李四 | B |
| 王五 | C |
| 高富帅 | D |
| 郑七 | E |
+--------+-------+
5 rows in set (0.00 sec)
mysql> select * from girl;
+--------+-------+
| gname | other |
+--------+-------+
| 空姐 | B |
| 大S | C |
| 阿娇 | D |
| 张柏芝 | D |
| 林黛玉 | E |
| 宝钗 | F |
+--------+-------+
6 rows in set (0.00 sec)
mysql> select boy.*,girl.* from
-> boy left join girl on boy.other=girl.other;
+--------+-------+--------+-------+
| bname | other | gname | other |
+--------+-------+--------+-------+
| 屌丝 | A | NULL | NULL |
| 李四 | B | 空姐 | B |
| 王五 | C | 大S | C |
| 高富帅 | D | 阿娇 | D |
| 高富帅 | D | 张柏芝 | D |
| 郑七 | E | 林黛玉 | E |
+--------+-------+--------+-------+
6 rows in set (0.00 sec)
mysql> #女生上台,带着另一半,没有另一半的,用NULL补齐
mysql> select boy.*,girl.* from
-> girl left join boy on boy.other=girl.other;
+--------+-------+--------+-------+
| bname | other | gname | other |
+--------+-------+--------+-------+
| 李四 | B | 空姐 | B |
| 王五 | C | 大S | C |
| 高富帅 | D | 阿娇 | D |
| 高富帅 | D | 张柏芝 | D |
| 郑七 | E | 林黛玉 &