View Single Post
  #6 (permalink)  
Old January 21st, 2005, 06:32 AM
leo_vinay leo_vinay is offline
Authorized User
 
Join Date: Aug 2003
Location: , , India.
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by ChrisScott
 Hi Leo,

This should do it...
Code:
SELECT DISTINCT u.UserId, u.username, u.fname, u.email, p.photoname, p.isactivated 
FROM users u INNER JOIN photos p ON u.UserId = p.UserId;
Chris thanks for the suggestion. But it doesn't solve the problem.
I also did it the same way. The reason it doesnt work is when you use distinct in the join condition then the distinct clause operates on the record level and not on the field level.
So here it will bring multiple records of the same person.
That is more than one record will be fetched from the photos table having the same UserID. Though the UserId are same but the other combination like the "photoname" make the records distinct from each other...hence no effect of the "DISTINCT" clause.

Anyways i found a way out...may be not that good,but it is effective.

select u.userid,u.username,u.email,p.photoname,p.isactiva ted from users u, photos p where u.userid=p.userid and p.id in (select max(id) as id from photos group by userid)

regards

Vinay

Reply With Quote