MySQL- 通过匹配引用从多个表中获取数据
MySQL- Fetch data from multiple tables by matching the reference
我尝试使用连接查询从不同的 table 中获取数据。但是即使有数据也没有返回任何结果。
学生管理员 table 有关于学生的详细信息。学生的学号是这个 table 中的主键。在所有结果table(即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'
有人可以帮助我更正此查询以获得我期望的结果吗?如果您不清楚,请告诉我。我可以解释。
提前致谢。
将您的查询修改为
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'
这应该符合您的愿望:
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'
你检查过驱动程序是否返回错误吗?
将您的查询格式化为可读的内容后,我得到了这个
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'
我尝试使用连接查询从不同的 table 中获取数据。但是即使有数据也没有返回任何结果。
学生管理员 table 有关于学生的详细信息。学生的学号是这个 table 中的主键。在所有结果table(即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'
有人可以帮助我更正此查询以获得我期望的结果吗?如果您不清楚,请告诉我。我可以解释。
提前致谢。
将您的查询修改为
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'
这应该符合您的愿望:
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'
你检查过驱动程序是否返回错误吗?
将您的查询格式化为可读的内容后,我得到了这个
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'