left join不能保证唯一

来源:互联网 发布:软件接口的种类 编辑:程序博客网 时间:2024/06/05 12:42

有2个表

t1 :

uid   name 

----------------

1       tom

2       marry


t2:

uid   goods

--------------------

1       fruit

1       notebook

2       car

1       clothes

3       box


select count(*)    from t1  left join t2 on t1.uid = t2.uid


结果竟然比t1的总数还多?


这是因为,uid在t1表里是唯一的,但在t2表不是唯一的,所以t2里面能与t1匹配的每一行都会复制一行:


uid    name goods

1  tom   fruit

1      tom         notebook

2 marray car

1 tom clothes





0 0