多表联合查询的SQL语句

多表联合查询SQL语句一: 

select dpt.`dept_namee`,
		dpt.`principal_name`,
		dpt.`unit_type`,
		info.`sys_name`,
		info.`dept_name`,
		info.`begin_use_time`,
		gd.`pro_grade`,
		gd.`pro_time`,
		gd.`jug_res`,
		gd.`gov_res`
		from depart as dpt
		left join info_sys as info on dpt.dept_namee = info.dept_namee
		left join grade as gd on info.dept_namee = gd.dept_namee

多表联合查询SQL语句二(这个查询语句是李大哥写的)

select sdpt.`name` as departName ,dpt.*,sys.*,g.* from info_sys as sys 
LEFT JOIN grade g on sys.id = g.infosys_id 
LEFT JOIN material m on g.id = m.grade_id
LEFT JOIN depart dpt on sys.dept_namee = dpt.dept_namee
LEFT JOIN sys_dept sdpt on dpt.dept_namee = sdpt.dept_id;

多表联合查询SQL语句三:

select info.`dept_namee`,
		dpt.`principal_name`,
		dpt.`unit_type`,
		info.`sys_name`,
		info.`dept_name`,
		info.`begin_use_time`,
		gd.`pro_grade`,
		gd.`pro_time`,
		gd.`jug_res`,
		gd.`gov_res`
		from depart as dpt
		left join info_sys as info on dpt.dept_namee = info.dept_namee
		left join grade as gd on dpt.dept_namee = gd.dept_namee
		and info.dept_namee = gd.dept_namee

这张表的查询语句是李大哥写的 

select info.* from depart as d LEFT JOIN info_sys as info on d.id = info.dept_name 
left join grade g on info.id = g.sysinfo_id 
left join matarial m on g.id = m.grade_id
where d.detail_address='详细地址' or g.name='';

 

你可能感兴趣的:(SQL语句,MySQL数据库)