简体   繁体   English

从不同的表中选择列

[英]Selecting columns from different tables

I need to display two columns from my attendance table (MEMBER_ID & MEETING_ID) and one column from my meeting table and finally two columns from my member table which displays the names that match with MEETING_ID. 我需要显示我的出席表中的两列(MEMBER_ID和MEETING_ID),以及我的会议表中的一列,最后是我的成员表中的两列,其中显示与MEETING_ID匹配的名称。

The attendance table has a composite key (MEMBER_ID*, MEETING_ID*) 出席表有一个组合键(MEMBER_ID *,MEETING_ID *)

The member table's primary key is MEMBER_ID 成员表的主键是MEMBER_ID

Meeting table's primary key is MEETING_ID 会议桌的主键是MEETING_ID

My attempt is not working, can someone please help? 我的尝试没有用,有人可以帮忙吗?

SELECT MEMBER_ID, MEETING_ID, MEETING_NAME MEMBER_FIRSTNAME, MEMBER_LASTNAME
FROM ATTENDANCE, MEMBER, MEETING
WHERE MEETING.MEMBER_ID = MEETING.MEMBER_ID;

End result needs to be: 最终结果必须为:

MEMBER_ID    MEETING_ID   MEETING_NAME     FIRSTNAME    LASTNAME
0001         MEET0004     SPORTS DAY      JOHN         SMITH

May be you need this. 可能您需要这个。

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;
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
;

Use Explicit Join Syntax and then setup your relationships using the ON conditions and the keys between the tables. 使用“显式联接语法”,然后使用“打开”条件和表之间的键设置关系。 Note I also used table aliases to shorten typying. 注意我还使用表别名来缩短键入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM