brown2005 Posted November 10, 2009 Share Posted November 10, 2009 How do I select all users from users table where there users_id is not stored in the block table Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/ Share on other sites More sharing options...
gevans Posted November 10, 2009 Share Posted November 10, 2009 SELECT * FROM `users` WHERE `id` <> IN (SELECT `usersId` FROM `block`) Something along the lines of that will do it for you Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954805 Share on other sites More sharing options...
brown2005 Posted November 10, 2009 Author Share Posted November 10, 2009 SELECT * FROM users WHERE user_id <> IN (SELECT blocked_blocked FROM block) ORDER BY user_name ASC i have tried that but does not work Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954818 Share on other sites More sharing options...
gevans Posted November 10, 2009 Share Posted November 10, 2009 Try it with the NOT operator; SELECT * FROM users WHERE user_id NOT IN (SELECT blocked_blocked FROM block) ORDER BY user_name ASC Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954829 Share on other sites More sharing options...
brown2005 Posted November 10, 2009 Author Share Posted November 10, 2009 SQL query: SELECT * FROM users WHERE user_id NOT IN ( SELECT blocked_blocked FROM blocked ) ORDER BY user_name AS LIMIT 0 , 30 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS LIMIT 0, 30' at line 1 Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954838 Share on other sites More sharing options...
gevans Posted November 10, 2009 Share Posted November 10, 2009 You have AS instead of ASC Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954843 Share on other sites More sharing options...
brown2005 Posted November 10, 2009 Author Share Posted November 10, 2009 oh yes. damn sorry. thanks for the help. works fine. also if in the future i wanted to add say a filter as will, like display blocked_user from blocked where = $_SESSION['session_id']; how would I change the code. Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954845 Share on other sites More sharing options...
brown2005 Posted November 10, 2009 Author Share Posted November 10, 2009 SELECT * FROM users WHERE user_id NOT IN (SELECT blocked_blocked FROM blocked WHERE blocked_user=$session_id) ORDER BY user_name ASC I have worked out like that. I presume it is correct as it works. Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954848 Share on other sites More sharing options...
gevans Posted November 10, 2009 Share Posted November 10, 2009 Yes that's fine. I would adda condition to make sure you don't attempt to do that when the filtering is not wanted though! Link to comment https://forums.phpfreaks.com/topic/180973-select-from-users-where-users-are-not-in-blocked/#findComment-954861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.