我想SELECT SELECT PROJECT_ID,STAFF_ID,HARDWARE_ID和SOFTWARE_ID都鏈接在一個表ASSIGNMENTS中,但我想顯示該鏈接,同時還顯示鏈接到相關ID(例如STAFF_NAME,JOB_TYPE,來自STAFF表的JOB_GRADE)。這裏是我的代碼:如何從多個表中選擇多個值?
CREATE TABLE PROJECT
(PROJECT_ID CHAR(5) NOT NULL,
PROJECT_NAME CHAR(20),
PROJECT_TYPE CHAR(20),
START_DATE DATE,
END_DATE DATE,
PRIMARY KEY (PROJECT_ID));
CREATE TABLE HARDWARE
(HARDWARE_ID CHAR(5) NOT NULL,
HARDWARE_NAME CHAR(20),
PRIMARY KEY (HARDWARE_ID));
CREATE TABLE SOFTWARE
(SOFTWARE_ID CHAR(5) NOT NULL,
SOFTWARE_NAME CHAR(20),
PRIMARY KEY (SOFTWARE_ID));
CREATE TABLE STAFF
(STAFF_ID CHAR(5) NOT NULL,
STAFF_NAME CHAR(20),
JOB_TYPE CHAR(20),
JOB_GRADE CHAR(20),
PRIMARY KEY (STAFF_ID));
CREATE TABLE ASSIGNMENTS
(ASSIGNMENT_ID CHAR(5) NOT NULL,
PROJECT_ID CHAR(5),
STAFF_ID CHAR(5),
HARDWARE_ID CHAR(5),
SOFTWARE_ID CHAR(5),
PRIMARY KEY (ASSIGNMENT_ID),
FOREIGN KEY (PROJECT_ID) REFERENCES PROJECT(PROJECT_ID),
FOREIGN KEY (STAFF_ID) REFERENCES STAFF(STAFF_ID),
FOREIGN KEY (HARDWARE_ID) REFERENCES HARDWARE(HARDWARE_ID),
FOREIGN KEY (SOFTWARE_ID) REFERENCES SOFTWARE(SOFTWARE_ID));
下面是一些基本的數據:
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_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'.
是不是這個問題你發佈1小時前? – Aleksej
它雖然略有更新,使其更清晰。對不起,重複的,我只是不完全明白如何從前面的問題的答案。 – JadstaSeven
如果對問題的回答不清楚,請在回答中添加評論以要求澄清,或者等待更清晰的回答。發佈兩次相同的問題並不是一個好方法。鑑於您在此接受了答案,請關閉另一個問題。 – Aleksej