读完需要9分钟
速读仅需7分钟
对于很多同学来说,写SQL时的表关联看起来是一件很简单的事情,知道逻辑,有预期的结果,好像没什么特别要注意的,今天在写一条SQL逻辑的时候,觉得对于left join的部分还是存在一些误解...为了演示方便,我用两张表来说明,test1和test2....),(2,'bb'),(3,'cc'),(4,'bb'),(5,'bb');
insert into test2 values(2,'bb'),(3,'cc'),(4,'bb'),(6,'dd');
表中的数据如下...join的SQL,这个时候我们使用name='bb'来作为过滤条件,id作为关联条件。...mysql> select t1.id,t1.name from test1 t1 left join test2 t2 on t1.id=t2.id and t1.name='bb';
+----+