标签:nan 分享 htm div hang sel strong default sch
MYSQL
JOIN
mysql> mysql> desc College; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | cname | varchar(50) | NO | PRI | NULL | | | state | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> desc Student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | sname | varchar(50) | NO | PRI | NULL | | | school | varchar(50) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select * from College; +----------+----------+ | cname | state | +----------+----------+ | swj | sichuan | | nanchang | jiangsu | | nannong | jiangsu | | beida | beijing | | jiaoda | shanghai | +----------+----------+ 5 rows in set (0.00 sec) mysql> select * from Student; +-------+----------+ | sname | school | +-------+----------+ | bai | swj | | li | nanchang | | wang | beida | | he | masheng | | zhao | zaodao | +-------+----------+ 5 rows in set (0.00 sec) mysql>
mysql> SELECT * from College JOIN Student on College.cname = Student.school; +----------+---------+-------+----------+ | cname | state | sname | school | +----------+---------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | +----------+---------+-------+----------+ 3 rows in set (0.00 sec) mysql> SELECT * from College INNER JOIN Student on College.cname = Student.school; +----------+---------+-------+----------+ | cname | state | sname | school | +----------+---------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | +----------+---------+-------+----------+ 3 rows in set (0.00 sec) mysql> select * from College,Student where College.cname = Student.school; +----------+---------+-------+----------+ | cname | state | sname | school | +----------+---------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | +----------+---------+-------+----------+ 3 rows in set (0.00 sec) mysql> SELECT * from College STRAIGHT_JOIN Student on College.cname = Student.school; +----------+---------+-------+----------+ | cname | state | sname | school | +----------+---------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | +----------+---------+-------+----------+ 3 rows in set (0.00 sec)
mysql> SELECT * from College LEFT JOIN Student on College.cname = Student.school; +----------+----------+-------+----------+ | cname | state | sname | school | +----------+----------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | nannong | jiangsu | NULL | NULL | | beida | beijing | wang | beida | | jiaoda | shanghai | NULL | NULL | +----------+----------+-------+----------+ 5 rows in set (0.00 sec)
2. left join where
mysql> SELECT * from College LEFT JOIN Student on College.cname = Student.school where Student.sname is NULL; +---------+----------+-------+--------+ | cname | state | sname | school | +---------+----------+-------+--------+ | nannong | jiangsu | NULL | NULL | | jiaoda | shanghai | NULL | NULL | +---------+----------+-------+--------+ 2 rows in set (0.00 sec)
2.right join
mysql> SELECT * from College RIGHT JOIN Student on College.cname = Student.school; +----------+---------+-------+----------+ | cname | state | sname | school | +----------+---------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | | NULL | NULL | he | masheng | | NULL | NULL | zhao | zaodao | +----------+---------+-------+----------+ 5 rows in set (0.00 sec)
3. 模拟full out join
mysql> SELECT * from College LEFT JOIN Student on College.cname = Student.school union all SELECT * from College RIGHT JOIN Student on College.cname = Student.school; +----------+----------+-------+----------+ | cname | state | sname | school | +----------+----------+-------+----------+ | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | nannong | jiangsu | NULL | NULL | | beida | beijing | wang | beida | | jiaoda | shanghai | NULL | NULL | | swj | sichuan | bai | swj | | nanchang | jiangsu | li | nanchang | | beida | beijing | wang | beida | | NULL | NULL | he | masheng | | NULL | NULL | zhao | zaodao | | NULL | NULL | nu | NULL | +----------+----------+-------+----------+ 11 rows in set (0.00 sec)
标签:nan 分享 htm div hang sel strong default sch
原文地址:http://www.cnblogs.com/AlexBai326/p/6246764.html