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>

I think I got it:

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

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

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.!!

the f and m are synonyms for those tables the join is at the AND statement

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.