[英]MySql left outer join with condiction
I have two tables as 我有两张桌子
student_info(id,mobile,cTId,lvDate)
term_marks(tmId,stdId,cTId,marks,year)
Now I want to find out the all student id that are not present term_marks depending other checking, so I use this query but it returns all that matched and not matched two tables 现在我想找出所有不存在term_marks的学生id,这取决于其他检查,所以我使用这个查询,但它返回所有匹配的,不匹配的两个表
$sql = "select * from student_info si LEFT OUTER JOIN term_marks tm ON si.id=tm.stdId and si.cTId=tm.cTId AND tm.year=$year)
WHERE si.cTId=$cTId and si.lvDate=0";
Also I have tried it 我也试过了
$sql = "select * from student_info si left outer JOIN term_marks tm where si.id=tm.stdId
and si.cTId=tm.cTId and si.cTId=$cTId and tm.year=$year and si.lvDate=0";
Can you help me ? 你能帮助我吗 ?
SELECT si.*
FROM student_info si
WHERE si.cTId = $cTId
AND si.lvDate = 0
AND si.id NOT IN
(
SELECT tm.stdId
FROM term_marks tm
WHERE tm.year = $year
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.