我有以下查询,只有在连接存在时才返回数据。如何返回上一个连接表(#__unis)数据,即使这些表之间没有关系而不写另一个查询?
select * from #__unis_faculties AS faculty
join #__unis_subjects AS subject ON subject.faculty = faculty.id
join #__unis AS uni ON uni.id= subject.university
where uni.id = 1
答案 0 :(得分:1)
使用LEFT JOIN
代替join
select * from #__unis_faculties AS faculty
join #__unis_subjects AS subject ON subject.faculty = faculty.id
right join #__unis AS uni ON uni.id= subject.university
where uni.id = 1
答案 1 :(得分:0)
试试这个..
select * from #__unis_faculties AS faculty
join #__unis_subjects AS subject ON subject.faculty = faculty.id
left join #__unis AS uni ON ( uni.id= subject.university AND uni.id = 1 )