mysql查询,leftjoin(求并集),where(求交集)
准备(两张表t1,t2):
成都创新互联公司长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为石楼企业提供专业的成都网站建设、做网站,石楼网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。
表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)
分享题目:mysql查询,leftjoin(求并集),where(求交集)
URL分享:http://myzitong.com/article/pdsijd.html