我有3张桌子。以下是结构:
Student : SID,SNAME
Subject : SUID,SUNAME
Rid : SID,SUID
查询的结果应为:
SNAME SUNAME
答案 0 :(得分:2)
试试这个:
select st.SNAME
, sj.SUNAME
from Rid r
inner join Student st on r.SID = st.SID
inner join Subject sj on r.SUID = sj.SUID
答案 1 :(得分:1)
您有两个表和一个关系表。关系(Rid)表是关联其他两个(学生和主题)的表。您必须搜索学生和主题加入的Rid记录:
SELECT s.sname, sb.suname
FROM student s, subject sb, rid r
WHERE s.sid = r.sid AND sb.suid = r.suid;
或新款式
SELECT s.SNAME, sb.SUNAME
FROM Rid r
INNER JOIN Student s on r.SID = s.SID
INNER JOIN Subject sb on r.SUID = sb.SUID
答案 2 :(得分:1)
使用这个:
select st.SNAME, sj.SUNAME
from Rid r
left join Student st on r.SID = st.SID
left join Subject sj on r.SUID = j.SUID