Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrun 1 row from join statement

Status
Not open for further replies.

blar9

Programmer
Mar 12, 2007
39
US
Here is a query below I want to get all this information back plus some but the problem is the pictures. There can be more than 1 picture in the database. I just want to return the latest picture using pic.DateOfPicture so I dont get more than one row. I cannot use distinct because of the image listed.

SELECT Emp.EmployeeUID, pic.Picture, emp.FirstName, emp.LastName, pic.DateOfPicture
FROM emp_General emp Left Outer JOIN
Client_pictures pic ON Emp.EmployeeUID = pic.EmployeeUID
 
this is pseudo, you may have to tweak it

Code:
SELECT     Emp.EmployeeUID, pic.Picture, emp.FirstName, emp.LastName, Max(pic.DateOfPicture)
FROM       emp_General emp Left Outer JOIN
           Client_pictures pic ON Emp.EmployeeUID = pic.EmployeeUID
GROUP BY Emp.EmployeeUID, pic.Picture, emp.FirstName, emp.LastName
HAVING pic.DateOfPicture = Max(pic.DateOfPicture)

-The answer to your problem may not be the answer to your question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top