mysql查询,left join(求并集),where(求交集)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql查询,left join(求并集),where(求交集)相关的知识,希望对你有一定的参考价值。

准备(两张表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)


以上是关于mysql查询,left join(求并集),where(求交集)的主要内容,如果未能解决你的问题,请参考以下文章

EXCEL中如何求并集

SQL中的join连接查询

求并集

delphi将两个Strlist合并,求并集

join,left join,inner join的区别?

顺序表[求并集 方法更新]