While fetching data from 3 tables using join I get an error: Column 'semester' and 'department' in field list is ambiguous
While fetching data from 3 tables using join I get an error: Column 'semester' and 'department' in field list is ambiguous
所有三个 table 包含 'semester' 和 'department' 列
SELECT DISTINCT
test_name,
fname,
lname,
rno
FROM exam_attempted_list
INNER JOIN stud_test ON
exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg ON
exam_attempted_list.student_id = stud_reg.student_id WHERE semester='2nd' AND department='cse'
使用 table 别名,例如 exam_attempted_list.semester='2nd'
SELECT DISTINCT test_name ,fname, lname ,rno
FROM
exam_attempted_list
INNER JOIN stud_test ON exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg ON exam_attempted_list.student_id = stud_reg.student_id
WHERE exam_attempted_list.semester='2nd' AND exam_attempted_list.department='cse';
使用以下格式,即您的查询中有一些语句重复,语句中缺少别名:
SELECT DISTINCT exam_attempted_list.test_name ,exam_attempted_list.fname,
exam_attempted_list.lname , exam_attempted_list.rno
FROM exam_attempted_list
INNER JOIN stud_test
ON exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg
ON exam_attempted_list.student_id = stud_reg.student_id
WHERE semester='2nd' AND department='cse'
SELECT DISTINCT eal.test_name , eal.fname, eal.lname , eal.rno
FROM exam_attempted_list AS eal
INNER JOIN stud_test AS st ON eal.student_id = st.student_id
INNER JOIN stud_reg AS sr ON eal.student_id = sr.student_id
WHERE eal.semester='2nd' AND eal.department='cse'
将 eal
替换为 st
或 sr
,具体取决于您希望从何处获取数据。
所有三个 table 包含 'semester' 和 'department' 列
SELECT DISTINCT
test_name,
fname,
lname,
rno
FROM exam_attempted_list
INNER JOIN stud_test ON
exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg ON
exam_attempted_list.student_id = stud_reg.student_id WHERE semester='2nd' AND department='cse'
使用 table 别名,例如 exam_attempted_list.semester='2nd'
SELECT DISTINCT test_name ,fname, lname ,rno
FROM
exam_attempted_list
INNER JOIN stud_test ON exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg ON exam_attempted_list.student_id = stud_reg.student_id
WHERE exam_attempted_list.semester='2nd' AND exam_attempted_list.department='cse';
使用以下格式,即您的查询中有一些语句重复,语句中缺少别名:
SELECT DISTINCT exam_attempted_list.test_name ,exam_attempted_list.fname,
exam_attempted_list.lname , exam_attempted_list.rno
FROM exam_attempted_list
INNER JOIN stud_test
ON exam_attempted_list.student_id = stud_test.student_id
INNER JOIN stud_reg
ON exam_attempted_list.student_id = stud_reg.student_id
WHERE semester='2nd' AND department='cse'
SELECT DISTINCT eal.test_name , eal.fname, eal.lname , eal.rno
FROM exam_attempted_list AS eal
INNER JOIN stud_test AS st ON eal.student_id = st.student_id
INNER JOIN stud_reg AS sr ON eal.student_id = sr.student_id
WHERE eal.semester='2nd' AND eal.department='cse'
将 eal
替换为 st
或 sr
,具体取决于您希望从何处获取数据。