Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601

    Unanswered: Two SELECT statements

    Hi,

    Is it possible to have two SELECT statements? I am trying to troubleshoot

    Code:
    SELECT Buddies.EmployeesID, Employees.FirstName, Employyes.LastName
    FROM Buddies
    INNER JOIN Employees 
    ON Buddies.Buddy_EmployeesID=Employees.EmployeesID
    INNER JOIN  Buddies
    ON Buddies.EmployeesID=Employees.EmployeesID;
    The original to that was
    Code:
    SELECT Buddies.EmployeesID, Employees.FirstName, Employees.LastName
    FROM Buddies
    INNER JOIN Employees ON Buddies.Buddy_EmployeesID=Employees.Buddy2_ID,
    Buddies.EmployeesID=Employees.Buddy2_ID;
    And finally the original to that was
    Code:
    SELECT Buddies.EmployeesID, Buddies.Buddy_EmployeesID,
    Employees.FirstName, Employees.LastName
    FROM Buddies INNER JOIN Employees 
    ON Buddies.Buddy_EmployeesID=Employees.EmployeesID, 
    Buddies.EmployeesID=Employees.EmployeesID;
    Any help would be great

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'm kind of taking off at right angles, trying to get to what I think you want instead of trying to follow your code. It looks like you've got a buddies table that links two employees, and you want to query each employee with their buddy. If so, I'd use something like:
    Code:
    SELECT e.EmployeesId, e.FirstName, e.LastName
    ,  b.EmployeesId, b.FirstName, b.LastName
       FROM buddies AS z
       INNER JOIN Employees AS e
          ON (e.employeesId = z.employeesId)
       INNER JOIN Employees AS b
          ON (b.EmployeesId = z.Buddy_EmployeesId)
    -PatP

  3. #3
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    Man Pat you are good. I am looking for that exactly, but also their respected positions (engineer, etc). I assume the e. and the b. just indexes stuff

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I didn't see anything in your queries that even reference positions!

    What I did was create a three table join, where the buddy table joined to the employees table twice. The "e." prefix is used for the employee, and the "b." prefix is used for the employee's buddy. If you can figure out their position from their row in Employees, then you are "good to go" as far as I can tell.

    -PatP

  5. #5
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    That code didn't work. How would I do a double join:?

Posting Permissions

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