MySQL - joining multiple tables

How can I alter the SELECT query to only show id's for users that match my friends table.
For example if my id is "17" and my list of friends is produced from query "SELECT toid FROM `friends` WHERE fromid = '17'"

This would return 2012,2004,2002,2013,2006 which I then want to extract user information by joining 5 other tables.

  `id` int(11) NOT NULL auto_increment,
  `toid` int(11) NOT NULL,
  `fromid` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)

-- Dumping data for table `friends`

INSERT INTO `friends` (`id`, `toid`, `fromid`) VALUES
(1, 2012, 17),
(2, 17, 2012),
(3, 2004, 17),
(4, 17, 2004),
(5, 2002, 17),
(6, 17, 2002),
(9, 2013, 17),
(10, 17, 2013),
(11, 2005, 2014),
(12, 2014, 2005),
(13, 2006, 2014),
(14, 2014, 2006),
(15, 2006, 17),
(16, 17, 2006);

I need the query below to display user information for the following id's 2012,2004,2002,2013,2006

u.sess_id AS sess_id,
u.username AS username,
u.session_last_active AS last_active, AS email, AS contact,
profile.countryLive AS country,
profile.stateLive AS state,
profile.cityLive AS city,
profile.updated AS profile_upd,
profile.birthdate_day AS birthdate_day,
profile.birthdate_month AS birthdate_month,
profile.birthdate_year AS birthdate_year,
profile.gender AS gender,
profile.updated AS profile_upd,
personality.updated AS personality_upd,
photos.image1 AS image1,
photos.updated AS photos_upd,
video.updated AS video_upd FROM users AS u INNER JOIN
user_upd_personality AS personality,
user_upd_my_profile AS profile,
user_upd_photos AS photos,
user_upd_video AS video
WHERE profile.updated = 1
AND photos.updated = 1
AND id = personality.user_id
AND id = profile.user_id
AND id = photos.user_id
AND id = video.user_id
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can do this with a condition like:

where id in ( SELECT toid FROM `friends` WHERE fromid = '17' )

hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sabecsAuthor Commented:
Thanks angelIII.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.