我需要在我的考勤表(MEMBER_ID& MEETING_ID)中显示两列,从会议表中显示一列,最后从我的成员表中显示两列,显示与MEETING_ID匹配的名称。
考勤表有一个复合键(MEMBER_ID *,MEETING_ID *)
会员表的主键是MEMBER_ID
会议桌的主键是MEETING_ID
我的尝试无效,有人可以帮忙吗?
SELECT MEMBER_ID, MEETING_ID, MEETING_NAME MEMBER_FIRSTNAME, MEMBER_LASTNAME
FROM ATTENDANCE, MEMBER, MEETING
WHERE MEETING.MEMBER_ID = MEETING.MEMBER_ID;
最终结果必须是:
MEMBER_ID MEETING_ID MEETING_NAME FIRSTNAME LASTNAME
0001 MEET0004 SPORTS DAY JOHN SMITH
答案 0 :(得分:1)
可能你需要这个。
SELECT A.MEMBER_ID, A.MEETING_ID, M2.MEETING_NAME, M1.MEMBER_FIRSTNAME, M1.MEMBER_LASTNAME
FROM ATTENDANCE A, MEMBER M1, MEETING M2
WHERE M1.MEMBER_ID = A.MEMBER_ID
AND A.MEETING_ID = M2.MEETING_ID;
答案 1 :(得分:1)
SELECT
a.MEMBER_ID
,a.MEETING_ID
,mt.MEETING_NAME
,mb.MEMBER_FIRSTNAME
,mb.MEMBER_LASTNAME
FROM
ATTENDANCE a
INNER JOIN MEMBER mb
ON a.MEMBER_ID = mb.MEMBER_ID
INNER JOIN MEETING mt
ON a.MEETING_ID = mt.MEETING_ID
;
使用显式连接语法,然后使用ON条件和表之间的键设置关系。注意我也使用表别名来缩短打字。