sql 多表查询相关
走查代码时看到以下的sql.from 后接两个表用where连接。
看了会,想不出为什么这么写的理由,因为既然已经用inner join了完全可以都改用此方式.
而且改过后的效率还更高
select d.*,(select count(*) from Tab_Dailyreport_Loginfo c where c.info_parentid = d.info_id) count,u.user_truename userName,u.user_photos userPhotos,u.user_sex userSex,de.dept_name userDeptName from tab_uum_dept de, tab_dailyreport_loginfo d inner join view_dailyreport_user u on d.info_userid = u.user_id where de.dept_id = u.depart_id and d.INFO_TYPE = 1 order by d.INFO_DATE desc------------改成全部inner joinselect d.*,(select count(*) from Tab_Dailyreport_Loginfo c where c.info_parentid = d.info_id) count,u.user_truename userName,u.user_photos userPhotos,u.user_sex userSex,de.dept_name userDeptName FROM tab_dailyreport_loginfo d inner join view_dailyreport_user u on d.info_userid = u.user_id inner join tab_uum_dept de on de.dept_id = u.depart_id and d.INFO_TYPE = 1 order by d.INFO_DATE desc