我尝试使用join查询从不同的表中获取数据。但即使有数据,它也不会返回任何结果。
“学生主表”包含有关该学生的详细信息。学生的学籍号码是本表的主键。将滚动号添加到所有结果表(即first_term_results、second_term_results等)中以供参考。
因此,为了获取学生的详细信息,他的第一学期和第二学期的成绩,我使用以下查询,没有给出预期的结果。我正在尝试获取与roll_no匹配的细节。
SELECT a.*, b .*,c.*
FROM student_master AS a
INNER JOIN first_term_results AS b
INNER JOIN second_term_results AS c
ON a.roll_no = b.roll_no = c.roll_no
WHERE a.roll_no = '53'
AND b.roll_no='53'
AND c.roll_no = '53'有人能帮我纠正这个查询,得到我期待的结果?.Also,请告诉我,如果我是不清楚的。我可以解释。
提前谢谢。
发布于 2015-08-11 18:48:14
在将查询格式化为可读的内容之后,我得到以下内容
SELECT a.*, b .*,c.*
FROM student_master AS a
INNER JOIN first_term_results AS b
INNER JOIN second_term_results AS c ON a.roll_no = b.roll_no = c.roll_no
WHERE a.roll_no = '53'
AND b.roll_no='53'
AND c.roll_no = '53'对我来说有点奇怪,我会去做这样的事情
SELECT a.*, b .*,c.*
FROM student_master AS a
INNER JOIN first_term_results AS b on a.roll_no = b.roll_no
INNER JOIN second_term_results AS c ON a.roll_no = c.roll_no
WHERE a.roll_no = '53' 发布于 2015-08-11 18:46:00
将查询修改为
SELECT a.*, b.*,c.*
FROM student_master AS a
INNER JOIN first_term_results AS b ON a.roll_no = b.roll_no
INNER JOIN second_term_results AS c ON a.roll_no = c.roll_no
WHERE a.roll_no = '53'发布于 2015-08-11 18:46:30
这应该符合你的愿望:
SELECT a.*, b .*,c.*
FROM student_master AS a
LEFT JOIN first_term_results AS b ON(a.roll_no = b.roll_no)
LEFT JOIN second_term_results AS c ON( a.roll_no = c.roll_no)
WHERE a.roll_no = '53'您是否检查了驱动程序返回的错误?
https://stackoverflow.com/questions/31949568
复制相似问题