user3553846
user3553846

Reputation: 342

SELECT clause with three tables together

Example, having these 3 tables

DEPARTMENT

//DEPARTMENT
DNAME       BUDGET      CHAIRMAN
----------------------------------
RESEARCH     2000         JOHN
   IT        3000          MAY
 SCIENCE     5000         KING

PROJECT

//PROJECT
P#     TITLE     BUDGET    STARTD          ENDD
----------------------------------------------------
1      COMPUTING   200     13-10-1993      13-11-1993
2       CODING     300     15-10-1993      15-12-1993
3      SEARCHING   188     07-07-1995      08-08-1995

DP <--Assume constraint references done already, just didn't show the coding here

//DP
DNAME        P#
----------------
RESEARCH      1
  IT          2
RESEARCH      3

SO when i run this statement

SELECT d.DNAME,d.BUDGET,d.CHAIRMAN,p.TITLE,p.BUDGET,p.STARTD,p.ENDD 
     FROM DEPARTMENT d INNER JOIN PROJECT p 
     INNER JOIN DP dp ON DP.P#=p.P#;

but show some errors. want to get output like this: Only display those involved in the project tables

DNAME    BUDGET   CHAIRMAN     TITLE      BUDGET     STARTD        ENDD
---------------------------------------------------------------------------
RESEARCH  2000     JOHN       COMPUTING    200       13-10-1993  13-11-1993
RESEARCH  2000     JOHN       SEARCHING    188       07-07-1995  08-08-1995
   IT     3000      MAY         CODING     300       15-10-1993  15-12-1993

Upvotes: 0

Views: 38

Answers (1)

G one
G one

Reputation: 2729

Change the query to:

SELECT d.DNAME,d.BUDGET,d.CHAIRMAN,p.TITLE,p.BUDGET,p.STARTD,p.ENDD 
     FROM DEPARTMENT d INNER JOIN dp on dp.dname=d.dname
     INNER JOIN project p ON DP.P=p.P;

fiddle

Upvotes: 1

Related Questions