这是我的询问..
SELECT tcs.tutor_id AS tid, tcs.category_id AS cid, tcs.subject_id AS sid, GROUP_CONCAT( DISTINCT s.subjects SEPARATOR ', ') AS subjects,
t.tutor_name, t.tutor_code AS tcode, DATE_FORMAT(t.registration_date, '%b %D, %Y') AS date, t.qualification,
GROUP_CONCAT( DISTINCT o.option_name SEPARATOR ', ') AS tutor_option, timg.image_name AS img
FROM tutor_category_subject as tcs
INNER JOIN subject AS s ON tcs.subject_id = s.subject_id
INNER JOIN tutor_option AS toption ON toption.tutor_id = tcs.tutor_id
INNER JOIN options AS o ON toption.option_id = o.option_id
INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id
LEFT JOIN tutor_images AS timg ON timg.tutor_id = tcs.tutor_id
WHERE s.subjects LIKE '%business%' AND timg.image_type = 'profile'
GROUP BY tcs.tutor_id;
此查询正常工作..但是timg的image_type coloum存在问题。这是导师可能有他们的个人资料图片和一些导师没有个人资料图片。但即使不是他们的个人资料图片,我也需要选择具有这种条件的所有导师。在这个查询中,如果导师没有选择的导演没有个人资料图像...那么我该怎么办呢?
任何评论都非常感谢。 谢谢
答案 0 :(得分:3)
您只需将WHERE
子句中的过滤器移至JOIN
的{{1}}子句:
tutor_images
答案 1 :(得分:1)
您也可以在WHERE
部分执行此操作:
WHERE s.subjects LIKE '%business%' AND (timg.image_type = 'profile' OR timg.image_type is NULL)