MYSQL LETT/RIGHT/INNER/FUll JOIN 注意事项

 

 1、JOIN ON .....AND 这个and是在连表时起到筛选作用,不作为连表后的整体筛选条件,如下:

  

select count(*) from 
dmp_company_count 
LEFT JOIN (select * from dmp_data_company where functional=17) dmp_data_company ON dmp_company_count.keyno = dmp_data_company.keyno AND dmp_company_count.patent!=0
LEFT JOIN dmp_company A ON dmp_data_company.keyno=A.keyno 
LEFT JOIN dmp_functional ON dmp_functional.id = dmp_data_company.functional 
WHERE A.type= 1 and A.st= 1

 

2、将连表条件放到 where 关键词后面时是整体筛选,不要搞迷了

select count(*) from 
dmp_company_count 
LEFT JOIN (select * from dmp_data_company where functional=17) dmp_data_company ON dmp_company_count.keyno = dmp_data_company.keyno 
LEFT JOIN dmp_company A ON dmp_data_company.keyno=A.keyno 
LEFT JOIN dmp_functional ON dmp_functional.id = dmp_data_company.functional 
WHERE A.type= 1 and A.st= 1 AND dmp_company_count.patent!=0

 

 

posted on 2020-01-15 14:43  滚动的蛋  阅读(239)  评论(0编辑  收藏  举报

导航