我试过的代码:
SELECT *FROM loans LEFT JOIN users ON loans.user_id=users.user_id
(
IF student_ID='1' THEN (SELECT *FROM teacher)
ELSE (SELECT *FROM student)
)
代码无法正常运行。我希望loans
显示student
中的teacher
或users
名称。我尝试过similia工作,但它也不起作用。
答案 0 :(得分:0)
试试这个:
select *
from loans l
left join users u on l.user_id = users.user_id
left join teacher t on u.teacher_id = t.teacher_id and u.student_id = 1
left join student s on u.student_id = s.student_id and u.student_id <> 1
<强>解释强>