Lets assume two tables:
STUDENTS:
id | name | faculty_id  
and:
FACULTIES:
id | name
I am trying to query for students by students.id and also return faculties.name where students.faculty_id = faculties.id.
I used:
SELECT students.*, faculties.name FROM students 
JOIN faculties on students.faculty_id = faculties.id
WHERE students.id = ' ... ';
This works well, however there is a problem:
If, by some mistake, the student was assigned a non-existent faculty_id than he would never be found. I would like to write more 'flexible' query that would return faculty.name only if match is found, otherwise just leave it empty.
Also, the query has to have no memory intensive loops, since you could query by name, etc... which results in large number of matches.
 
     
     
    