+ Reply to Thread
Results 1 to 2 of 2

Subquery after Left Join

Hybrid View

Guest Subquery after Left Join 01-18-2006, 05:45 PM
Guest RE: Subquery after Left Join 01-19-2006, 10:55 AM
  1. #1
    Pontificateur
    Guest

    Subquery after Left Join

    All:

    I have a Personnel table and a Attendance table. I want to join the two,
    retrieving all employees but only specific attendance. The following query
    works without error, but only gives me employees with matching attendance
    records.

    SELECT p.p_empno, p.p_fname, p.p_lname, a.a_date, a.a_reason, a.a_comments
    FROM hrpersnl p LEFT JOIN
    hattran a ON p.p_empno = a.a_empno
    WHERE (p.p_active="A") and (a.a_date Between {d '2006-01-01'} And {d
    '2006-01-14'})

    To get a true left join, I used the following concept in Access, which
    worked perfectly. I simply replace the joined table with a subquery and
    moved the "where" clause. When I try it in MS Query, I get a "Syntax Error"
    message.

    SELECT p.p_empno, p.p_fname, p.p_lname, a.a_date, a.a_reason, a.a_comments
    FROM hrpersnl p LEFT JOIN
    (SELECT * FROM hattran a
    WHERE (a.a_date Between {d '2006-01-01'} And {d '2006-01-14'})) a
    ON p.p_empno = a.a_empno
    WHERE p.p_active="A"


    Is there a way I can make this concept work?

    Thanks!

    greg


  2. #2
    Pontificateur
    Guest

    RE: Subquery after Left Join

    Sorry to rephrase, but I've simplified the issue:

    This works...
    SELECT p_empno, a_empno
    FROM hrpersnl LEFT JOIN hattran
    ON p_empno = a_empno

    This works in Access, but gives syntax error in Excel query...
    SELECT p_empno, a_empno
    FROM hrpersnl LEFT JOIN (Select * from hattran)
    ON p_empno = a_empno

    The only difference is the query after the join. Is this really a syntax
    error, or just not allowed in MS Query!?

    Thanks again!




    "Pontificateur" wrote:

    > All:
    >
    > I have a Personnel table and a Attendance table. I want to join the two,
    > retrieving all employees but only specific attendance. The following query
    > works without error, but only gives me employees with matching attendance
    > records.
    >
    > SELECT p.p_empno, p.p_fname, p.p_lname, a.a_date, a.a_reason, a.a_comments
    > FROM hrpersnl p LEFT JOIN
    > hattran a ON p.p_empno = a.a_empno
    > WHERE (p.p_active="A") and (a.a_date Between {d '2006-01-01'} And {d
    > '2006-01-14'})
    >
    > To get a true left join, I used the following concept in Access, which
    > worked perfectly. I simply replace the joined table with a subquery and
    > moved the "where" clause. When I try it in MS Query, I get a "Syntax Error"
    > message.
    >
    > SELECT p.p_empno, p.p_fname, p.p_lname, a.a_date, a.a_reason, a.a_comments
    > FROM hrpersnl p LEFT JOIN
    > (SELECT * FROM hattran a
    > WHERE (a.a_date Between {d '2006-01-01'} And {d '2006-01-14'})) a
    > ON p.p_empno = a.a_empno
    > WHERE p.p_active="A"
    >
    >
    > Is there a way I can make this concept work?
    >
    > Thanks!
    >
    > greg
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1