Adding a table to query?!

I’m trying to make an recepient list from several of tables. As it is now The script is getting all the users in the same group as the "asking ". Like this:

$sql = "SELECT
				u.new_userid
			  , u.fname
			  , u.lname
			  , u.email
			FROM fb_users u
			INNER JOIN fb_club_users cu
			ON cu.new_userid = u.new_userid
			INNER JOIN
			  (SELECT
				   clubid
			   FROM fb_club_users
			   WHERE new_userid = $userid
			  ) AS c
			ON c.clubid = cu.clubid
			WHERE u.new_userid <> $userid";

But I want to add another table to the query without the risk of getting duplicates. The new table looks as follows:

id, user, friend, active

I want top find all the current userfriends and get them into the query. But the user might have a friend which is also in a group. So how do I get all the friends out without making a duplkicate if the friend also is in one of the users groups?!?!?

Hope this makes sense…

Well… Solved it my self:

SELECT
				u.new_userid
			  , u.fname
			  , u.lname
			  , u.email
			FROM fb_users u
			INNER JOIN fb_user_friends uf
			ON uf.user = u.new_userid
			WHERE u.new_userid <> $userid
			UNION
			SELECT
				u.new_userid
			  , u.fname
			  , u.lname
			  , u.email
			FROM fb_users u
			INNER JOIN fb_club_users cu
			ON cu.new_userid = u.new_userid
			INNER JOIN
			  (SELECT
				   clubid
			   FROM fb_club_users
			   WHERE new_userid = $userid
			  ) AS c
			ON c.clubid = cu.clubid
			WHERE u.new_userid <> $userid

Maybe if you posted this in the ‘MySQL’ or '[URL=“http://www.sitepoint.com/forums/forumdisplay.php?f=88”]Databases’ forum, you would have received a faster response. :wink:

It might be worth remembering next time.