dlouis95 Posted October 11, 2010 Share Posted October 11, 2010 Hello all. Im making a new site and I've been doing good up until this one part that i never learned how to do. What i need to do is select posts (posts table) where the person that made the post is friends with me (friend table) and I would like it in order of it being made. So far the closest ive gotten in getting this is the code below SELECT * FROM `posts` WHERE `user_id`=(SELECT `friend_id` FROM `friend` WHERE user_id = ' #my id ') But this gave the error that I'm selecting more than one row, which I need to do. Is there any other way I can do this? Any help at all would be greatly appreciated. I'm using Mysql client version 5.1.50. Quote Link to comment https://forums.phpfreaks.com/topic/215652-mysql-subquery/ Share on other sites More sharing options...
DavidAM Posted October 12, 2010 Share Posted October 12, 2010 If you expect to have more than one friend, you can use IN instead of = : SELECT * FROM `posts` WHERE `user_id` IN (SELECT `friend_id` FROM `friend` WHERE user_id = ' #my id ') Quote Link to comment https://forums.phpfreaks.com/topic/215652-mysql-subquery/#findComment-1121289 Share on other sites More sharing options...
dlouis95 Posted October 12, 2010 Author Share Posted October 12, 2010 If you expect to have more than one friend, you can use IN instead of = : SELECT * FROM `posts` WHERE `user_id` IN (SELECT `friend_id` FROM `friend` WHERE user_id = ' #my id ') :D :D :D :D :D :D THANK YOU SOO SOOOO SOOOOOOOO MUCH. lol I wish my friends knewmysql more. Thanks you. =) Quote Link to comment https://forums.phpfreaks.com/topic/215652-mysql-subquery/#findComment-1121291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.