在这种情况下,左连接与右连接相同吗?
mysql>
mysql>
mysql> use usenet;show tables;describe ARTICLE;describe NEWSGROUP;
Database changed
+------------------+
| Tables_in_usenet |
+------------------+
| ARTICLE |
| NEWSGROUP |
+------------------+
2 rows in set (0.00 sec)
+---------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| MESSAGENUMBER | int(11) | YES | | NULL | |
| NEWSGROUP_ID | bigint(20) | YES | MUL | NULL | |
+---------------+------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| NEWSGROUP | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql>
mysql> select * from ARTICLE right join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID;
+------+---------------+--------------+----+-------------------------------+
| ID | MESSAGENUMBER | NEWSGROUP_ID | ID | NEWSGROUP |
+------+---------------+--------------+----+-------------------------------+
| 1 | 4 | 1 | 1 | gwene.com.androidcentral |
| 2 | 5 | 1 | 1 | gwene.com.androidcentral |
| 3 | 6 | 1 | 1 | gwene.com.androidcentral |
| 4 | 7 | 1 | 1 | gwene.com.androidcentral |
| 5 | 8 | 1 | 1 | gwene.com.androidcentral |
| 6 | 9 | 1 | 1 | gwene.com.androidcentral |
| 7 | 10 | 1 | 1 | gwene.com.androidcentral |
| 8 | 11 | 1 | 1 | gwene.com.androidcentral |
| 9 | 4 | 2 | 2 | gwene.com.blogspot.emacsworld |
| 10 | 4 | 3 | 3 | gwene.com.blogspot.googlecode |
| 11 | 5 | 3 | 3 | gwene.com.blogspot.googlecode |
| 12 | 6 | 3 | 3 | gwene.com.blogspot.googlecode |
| 13 | 7 | 3 | 3 | gwene.com.blogspot.googlecode |
| 14 | 8 | 3 | 3 | gwene.com.blogspot.googlecode |
| 15 | 9 | 3 | 3 | gwene.com.blogspot.googlecode |
| 16 | 10 | 3 | 3 | gwene.com.blogspot.googlecode |
| 17 | 11 | 3 | 3 | gwene.com.blogspot.googlecode |
| 18 | 4 | 4 | 4 | gwene.com.economist |
| 19 | 5 | 4 | 4 | gwene.com.economist |
| 20 | 6 | 4 | 4 | gwene.com.economist |
| 21 | 7 | 4 | 4 | gwene.com.economist |
| 22 | 8 | 4 | 4 | gwene.com.economist |
| 23 | 9 | 4 | 4 | gwene.com.economist |
| 24 | 10 | 4 | 4 | gwene.com.economist |
| 25 | 11 | 4 | 4 | gwene.com.economist |
+------+---------------+--------------+----+-------------------------------+
25 rows in set (0.00 sec)
mysql>
mysql> select * from ARTICLE left join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID;
+----+---------------+--------------+------+-------------------------------+
| ID | MESSAGENUMBER | NEWSGROUP_ID | ID | NEWSGROUP |
+----+---------------+--------------+------+-------------------------------+
| 1 | 4 | 1 | 1 | gwene.com.androidcentral |
| 2 | 5 | 1 | 1 | gwene.com.androidcentral |
| 3 | 6 | 1 | 1 | gwene.com.androidcentral |
| 4 | 7 | 1 | 1 | gwene.com.androidcentral |
| 5 | 8 | 1 | 1 | gwene.com.androidcentral |
| 6 | 9 | 1 | 1 | gwene.com.androidcentral |
| 7 | 10 | 1 | 1 | gwene.com.androidcentral |
| 8 | 11 | 1 | 1 | gwene.com.androidcentral |
| 9 | 4 | 2 | 2 | gwene.com.blogspot.emacsworld |
| 10 | 4 | 3 | 3 | gwene.com.blogspot.googlecode |
| 11 | 5 | 3 | 3 | gwene.com.blogspot.googlecode |
| 12 | 6 | 3 | 3 | gwene.com.blogspot.googlecode |
| 13 | 7 | 3 | 3 | gwene.com.blogspot.googlecode |
| 14 | 8 | 3 | 3 | gwene.com.blogspot.googlecode |
| 15 | 9 | 3 | 3 | gwene.com.blogspot.googlecode |
| 16 | 10 | 3 | 3 | gwene.com.blogspot.googlecode |
| 17 | 11 | 3 | 3 | gwene.com.blogspot.googlecode |
| 18 | 4 | 4 | 4 | gwene.com.economist |
| 19 | 5 | 4 | 4 | gwene.com.economist |
| 20 | 6 | 4 | 4 | gwene.com.economist |
| 21 | 7 | 4 | 4 | gwene.com.economist |
| 22 | 8 | 4 | 4 | gwene.com.economist |
| 23 | 9 | 4 | 4 | gwene.com.economist |
| 24 | 10 | 4 | 4 | gwene.com.economist |
| 25 | 11 | 4 | 4 | gwene.com.economist |
+----+---------------+--------------+------+-------------------------------+
25 rows in set (0.00 sec)
mysql>
mysql>