|
-
Jul 18th, 2005, 02:28 PM
#1
Thread Starter
Junior Member
Database Query Question
I have 3 tables
TABLE: EMP
PK - EMP-ID
- EMP-NAME
TABLE: ALTER
PK - EMP-ID
FK - EMP-ALTERNATE
TABLE: LIMIT
PK - EMP-ID
- EMP-LIMIT
And im trying to show every instance on the employees table.
I've got my query to work fine with 2 tables but i cannot get it to work with three.
this query returns only the instance where data exist in all three tables for the empID, if its not in each table it doesnt print it. This is my query .
SELECT dbo.EMPLOYEES.[emp-id], dbo.EMPLOYEES.[emp-name], dbo.[EMP-ALTERNATE].[ALTER-APPROVER], dbo.[EXC-LIMIT-ID].[EXC-LIMIT-AMT]
FROM dbo.EMPLOYEES RIGHT OUTER JOIN
dbo.[EMP-ALTERNATE] ON dbo.EMPLOYEES.[emp-id] = dbo.[EMP-ALTERNATE].[ALTER-ID] OUTER JOIN
dbo.[EXC-LIMIT-ID] ON dbo.EMPLOYEES.[emp-id] = dbo.[EXC-LIMIT-ID].[EXC-LIMIT-NUM]
-
Jul 18th, 2005, 02:44 PM
#2
Thread Starter
Junior Member
Re: Database Query Question
figures it out already, user FULL OUTER JOIN on all joins to return everything
-
Jul 18th, 2005, 07:09 PM
#3
Re: Database Query Question
gud for you. , now make this thread resolved.
-
Jul 19th, 2005, 07:16 AM
#4
Fanatic Member
Re: Database Query Question
Code:
SELECT dbo.EMPLOYEES.[emp-id]
, dbo.EMPLOYEES.[emp-name]
, dbo.[EMP-ALTERNATE].[ALTER-APPROVER]
, dbo.[EXC-LIMIT-ID].[EXC-LIMIT-AMT]
FROM dbo.EMPLOYEES LEFT JOIN dbo.[EMP-ALTERNATE] ON dbo.EMPLOYEES.[emp-id] = dbo.[EMP-ALTERNATE].[ALTER-ID]
LEFT JOIN dbo.[EXC-LIMIT-ID] ON dbo.EMPLOYEES.[emp-id] = dbo.[EXC-LIMIT-ID].[EXC-LIMIT-NUM]
Returns the same data, just looks a little cleaner with out all of the "OUTER" joins.
Chris
Master Of My Domain
Got A Question? Look Here First
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|