mysql - SQL query left join issue -
i making query not working properly.
my table details follows:
subarea:
id
fieldsofstudy
student_subarea:
id primary key,
student_id ,
student_subarea foreign key subarea id , student_subarea.
ask:
want accomplish obtain fields of study in 1 column , in column id of student if in class. otherwise, show null or something.
select a.`id` , a.`name` , a.`area_id` , u. * `subarea` left join student_subarea u on u.subarea_id = a.id u.student_id =50 or u.student_id null doing not helping @ all. tried use functions , subqueries without success. me.
the general rule left join , filtering put filtering clauses in on clause first table. may want:
select a.`id`, a.`name`, a.`area_id`, u. * `subarea` left join student_subarea u on u.subarea_id = a.id , u.student_id = 50; how remember logic? left join returns rows first table when there no match on second table. appears want.
the problem logic students other than student 50 match logic. so, rows filtered out.
Comments
Post a Comment