Results 1 to 4 of 4

Thread: Database Query Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    26

    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]

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    26

    Re: Database Query Question

    figures it out already, user FULL OUTER JOIN on all joins to return everything

  3. #3
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Database Query Question

    gud for you. , now make this thread resolved.

  4. #4
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    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
  •  



Click Here to Expand Forum to Full Width