mardi 14 juin 2016

SQL query left join issue

I am making a query but it is not working properly.

My table details are as follows:

Subarea:
id
Fieldsofstudy

student_subarea:
id primary key,
student_id ,
student_subarea Foreign key to subarea id and the student_subarea.

ASK:
What I want to accomplish is to obtain all fields of study in one column and in another column the id of the student if he is in the class. Otherwise, show null or something.

SELECT a.`id` ,  a.`name` , a.`area_id` , u. * 
FROM  `subarea` a
LEFT JOIN student_subarea u ON u.subarea_id = a.id
WHERE u.student_id =50
OR u.student_id IS NULL

Doing this is not helping at all. I tried to use functions and subqueries without any success. Could some help me.

Aucun commentaire:

Enregistrer un commentaire