Page 1 of 1

simple mysql join

Posted: Wed Oct 14, 2009 1:25 pm
by andym67
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.

I apologize that this should be very easy, but as I am very new to mysql and have not gotten anywhere with this, I would appreciate help. I am sure that if I could get this simple join down using my files I will soon have it mastered. Thanks so much.

Re: simple mysql join

Posted: Wed Oct 14, 2009 1:36 pm
by andym67
I think I have it:

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

Thanks to someones cheat sheet...! Man I was "close" all afternoon.

Re: simple mysql join

Posted: Wed Oct 14, 2009 1:37 pm
by andym67