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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple left join question

Status
Not open for further replies.

LucL

Programmer
Jan 23, 2006
117
US
I'm not sure if this has to do with the join statement or with table linking but here it goes.

I have 2 tables, 1 is with users, the other is a friends table (indicating which users are friends)...

Users (not complete, just to give idea):

u_id
u_email
u_password
u_handle
u_photo
PRIMARY KEY (u_id)

Friends table:

f_id
f_mhandle
f_fhandle
PRIMARY KEY (f_id)


Now, I don't store the user photo in the friends table for obvious reason, but I do store the "Friends Handle" and the "My Handle". u_ids are not stored for a reason.

Now, I want to somehow pull the u_photo from users table when I'm doing a query on the friends table so that I can pull a photo for each friend.

Current query: "SELECT * From friends WHERE f_fhandle=$friend ORDER BY f_id DESC LIMIT 1000"

No idea on how I can pull the photo for a user where friends.f_fhandle=users.u_handle. If necessary to add a photo column to the friends list I can do that but I don't want to store the actual photo there because its updated in the users table and I don't want to repopulate things.

I think there is a way to do this using JOIN command or using table linking, but I am not sure how to link tables on mysql.

Thanks!
Luc L.
 
Code:
select Friends.f_id
     , Friends.f_mhandle
     , Users.u_photo
  from Friends 
inner
  join Users
    on Users.u_handle = Friends.f_mhandle
 where Friends.f_fhandle = $friend 
order 
    by f_id desc limit 1000

r937.com | rudy.ca
 
With a tiny adjustment that seems to have done the trick.

Thanks a lot bro. Works like a charm now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top