准备(两张表t1,t2):
表t1:
mysql> select * from t1;
+-------+---------+
| t1_id | t1_name |
+-------+---------+
| 1 | t1_1 |
| 2 | t1_2 |
+-------+---------+
2 rows in set (0.02 sec)
表t2:
MysqL> select * from t2;
+-------+---------+
| t2_id | t2_name |
+-------+---------+
| 2 | t2_2 |
| 3 | t2_3 |
+-------+---------+
2 rows in set (0.03 sec)
并集实例:
MysqL> select t1.t1_id,t2.t2_id,t1.t1_name from t1 left join t2 on t1.t1_id=t2.t2_id;
+-------+-------+---------+
| t1_id | t2_id | t1_name |
+-------+-------+---------+
| 1 | NULL | t1_1 |
| 2 | 2 | t1_2 |
+-------+-------+---------+
2 rows in set (0.02 sec)
交集实例:
MysqL> select t1.t1_id,t2.t2_id,t1.t1_name from t1,t2 where t1.t1_id=t2.t2_id;
+-------+-------+---------+
| t1_id | t2_id | t1_name |
+-------+-------+---------+
| 2 | 2 | t1_2 |
+-------+-------+---------+
1 row in set (0.01 sec)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。