如何从多个表中选择多个值?

时间:2016-12-11 17:36:14

标签: sql oracle

我想SELECT PROJECT_ID,STAFF_ID,HARDWARE_ID和SOFTWARE_ID这些都在表ASSIGNMENTS中链接,但我想显示该链接,同时还显示链接到相关ID的每个相应表中的所有属性(例如STAFF_NAME,JOB_TYPE ,来自STAFF表的JOB_GRADE)。这是我的代码:

INSERT INTO PROJECT (PROJECT_ID, PROJECT_NAME, PROJECT_TYPE, START_DATE, END_DATE)
VALUES ('B0001','BIKESHOP.COM','WEB DEVELOPMENT',TO_DATE('15/01/17','DD/MM/YY'),TO_DATE('15/02/17','DD/MM/YY'));

INSERT INTO HARDWARE (HARDWARE_ID, HARDWARE_NAME)
VALUES ('H0001','WEBDEV PC1');

INSERT INTO SOFTWARE (SOFTWARE_ID, SOFTWARE_NAME)
VALUES ('S0001','COFFEECUP IDE');

INSERT INTO STAFF (STAFF_ID, STAFF_NAME, JOB_TYPE, JOB_GRADE)
VALUES ('ST001','JOHN MASON','WEB DEVELOPER','1');

INSERT INTO ASSIGNMENTS (ASSIGNMENT_ID, PROJECT_ID, STAFF_ID, HARDWARE_ID, SOFTWARE_ID)
VALUES ('A0001','B0001','ST001','H0001','S0001');

以下是一些基本数据:

PROJECT_ID, PROJECT_NAME, PROJECT_TYPE, START_DATE, END_DATE, STAFF_ID, STAFF_NAME, JOB_TYPE, JOB_GRADE, HARDWARE_ID, HARDWARE_NAME, SOFTWARE_ID, SOFTWARE_NAME 
as one row, all linked to PROJECT_ID = 'B0001'.

如何从链接到单个PROJECT_ID的所有表中选择所有属性以显示例如:

render()

1 个答案:

答案 0 :(得分:0)

我明白了,你需要为你详细说明。你走了:

select p.*,
    s.*,
    h.*,
    sf.*
from assignments a
inner join staff s on a.staff_id = s.staff_id
inner join software sf on a.software_id = sf.software_id
inner join hardware h on a.hardware_id = h.hardware_id
inner join project p on a.project_id = p.project_id
where a.project_id = 'A0001';