If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Two SELECT statements

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-04, 11:34
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
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
Reply With Quote
  #2 (permalink)  
Old 07-09-04, 11:45
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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
Reply With Quote
  #3 (permalink)  
Old 07-09-04, 16:51
rguy84 rguy84 is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 07-09-04, 21:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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
Reply With Quote
  #5 (permalink)  
Old 07-12-04, 14:02
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
That code didn't work. How would I do a double join:?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On