1

I have the following query which returns data only if the join exists. How do I return from the last joined table (#__unis) datas, even if there is no relationship between those tables without to write another query?

 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 

table structure http://sqlfiddle.com/#!2/19add

2 Answers 2

1

use LEFT JOIN instead of 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 
Sign up to request clarification or add additional context in comments.

3 Comments

I have been trying before but the array is empty
can you provide a fiddle example ?
you have created fiddle but there was no data in it. can you make some sample data in your fiddle.
0

Try this..

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 ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.