and Yan 18 study php-27th Day-about the difference between the inner connection

Source: Internet
Author: User
With Yan 18 study php-27th Day-the difference between the right and left inner joins
/**
Yan 18 public benefit PHP Training
Classroom Address: YY Channel 88354001
Learning Community: 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
(' Dick Silk ', ' A '),
(' John Doe ', ' B '),
(' Harry ', ' C '),
(' Gao Fu Shuai ', ' D '),
(' Zheng Qi ', ' 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
(' Stewardess ', ' B '),
(' Big s ', ' C '),
(' Gillian ', ' D '),
(' Cecilia Cheung ', ' D '),
(' Lin Daiyu ', ' E '),
(' Bao Chai ', ' F ');
Query OK, 6 rows affected (0.03 sec)
Records:6 duplicates:0 warnings:0


Mysql> select * from Boy;
+--------+-------+
| bname | Other |
+--------+-------+
| Cock Wire | A |
| John Doe | B |
| Harry | C |
| Ko Fu Handsome | D |
| Zheng Qi | E |
+--------+-------+
5 rows in Set (0.00 sec)


Mysql> select * from girl;
+--------+-------+
| Gname | Other |
+--------+-------+
| Stewardess | B |
| Big S | C |
| Gillian | D |
| Cecilia Cheung | D |
| Lin Daiyu | E |
| Bao Chai | F |
+--------+-------+
6 rows in Set (0.00 sec)


Mysql> Select boy.*,girl.* from
Boy left joins girl on Boy.other=girl.other;
+--------+-------+--------+-------+
| bname | Other | Gname | Other |
+--------+-------+--------+-------+
| Cock Wire | A | NULL | NULL |
| John Doe | B | Stewardess | B |
| Harry | C | Big S | C |
| Ko Fu Handsome | D | Gillian | D |
| Ko Fu Handsome | D | Cecilia Cheung | D |
| Zheng Qi | E | Lin Daiyu | E |
+--------+-------+--------+-------+
6 rows in Set (0.00 sec)


Mysql> #女生上台, with the other half, without the other half, with null
Mysql> Select boy.*,girl.* from
-Girl left Join boy on Boy.other=girl.other;
+--------+-------+--------+-------+
| bname | Other | Gname | Other |
+--------+-------+--------+-------+
| John Doe | B | Stewardess | B |
| Harry | C | Big S | C |
| Ko Fu Handsome | D | Gillian | D |
| Ko Fu Handsome | D | Cecilia Cheung | D |
| Zheng Qi | E | Lin Daiyu | E |
| NULL | NULL | Bao Chai | F |
+--------+-------+--------+-------+
6 rows in Set (0.00 sec)


Mysql> #注意, a LEFT join B, is not to say that a table must be on the right, just say in the query data, a table is the subject
Mysql> select * from Boy;
+--------+-------+
| bname | Other |
+--------+-------+
| Cock Wire | A |
| John Doe | B |
| Harry | C |
| Ko Fu Handsome | D |
| Zheng Qi | E |
+--------+-------+
5 rows in Set (0.00 sec)


Mysql> select Other,bname from Boy;
+-------+--------+
| Other | bname |
+-------+--------+
| A | Cock Wire |
| B | John Doe |
| C | Harry |
| D | Ko Fu Handsome |
| E | Zheng Qi |
+-------+--------+
5 rows in Set (0.00 sec)


Mysql> #女生上台, with the other half, without the other half, with null
Mysql> #不能用左连接来做
Mysql> #用右连接. Just a girl left join male
Mysql> #用右连接, just male right join girl
Mysql> Select boy.*,girl.*
-From
Boy right Join Girl
-On boy.other = Girl.other;
+--------+-------+--------+-------+
| bname | Other | Gname | Other |
+--------+-------+--------+-------+
| John Doe | B | Stewardess | B |
| Harry | C | Big S | C |
| Ko Fu Handsome | D | Gillian | D |
| Ko Fu Handsome | D | Cecilia Cheung | D |
| Zheng Qi | E | Lin Daiyu | E |
| NULL | NULL | Bao Chai | F |
+--------+-------+--------+-------+
6 rows in Set (0.01 sec)


Mysql> Select boy.*,girl.*
-From
Boy inner JOIN Girl
-On Boy.other=girl.other;
+--------+-------+--------+-------+
| bname | Other | Gname | Other |
+--------+-------+--------+-------+
| John Doe | B | Stewardess | B |
| Harry | C | Big S | C |
| Ko Fu Handsome | D | Gillian | D |
| Ko Fu Handsome | D | Cecilia Cheung | D |
| Zheng Qi | E | Lin Daiyu | E |
+--------+-------+--------+-------+
5 rows in Set (0.00 sec)


Mysql> exit




Yan 18 teacher is too humorous, yesterday's video is as follows:

http://www.tudou.com/programs/view/TVhY20adVL4/
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.