0

I need a bit of help with a mysql join query. I have tried and tried and keep getting unhelpful errors.

I have two mysql tables:

friends:
friend1 INT
friend2 INT

members:
member_id INT
name varchar
lname varchar


Basically I want to loop through friends and find all records where friend1 is my member_id and then get the details for friend2 from the members file. I need a query that will return the data in members IF members.member_id = friends.friend2 AND where friends.friend1 = 1.

Can any one help me here? I think if I could get the basic down I can expand from there, but dang if I am getting nowhere on this join <g>

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by andym67
0

I think I got it:

SELECT members . * 
FROM members
INNER JOIN friends ON members.member_id = friends.friend2
WHERE friends.friend1 =1

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2

try this i think it's just a little less complex than the inner join syntax

SELECT m . * 
FROM members m, friends f
WHERE f.friend1 =1
and m.member_id = f.friend2

Edited by baki100: n/a

0

Thanks - that works as well. Is your FROM statement simply assigning Mand F as the variable names for the rest, or is this somehow doing the join as well. I haven't seen a query like this one.

I appreciate the help and your input, Thanks.!!

0

Ok - I think I am getting it. thanks alot. I'll be sure to add to your rep.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.