rocoso Posted November 3, 2007 Share Posted November 3, 2007 Hi This query will select email address of members that have a picture. SELECT email FROM users a, useralbum b WHERE a.user_id=b.zuserid AND b.picnumber ='1' I would like to select email addresses of members who do not have a picture. b.picnumber ='0' or something like that is not going to work because if they never uploaded a picture they have no records in the useralbum table. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/ Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 Here you go SELECT email FROM users where userid not in (select user_id from useralbum) Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384096 Share on other sites More sharing options...
toplay Posted November 3, 2007 Share Posted November 3, 2007 Here you go SELECT email FROM users where userid not in (select user_id from useralbum) rajivgonsalves, based on rocoso post it would be this: SELECT email FROM users where user_id not in (select zuserid from useralbum) Also, here's another way: SELECT u.email FROM `users` u LEFT JOIN `useralbum` ua ON ua.zuserid = u.user_id WHERE ua.zuserid IS NULL ; Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384133 Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 sorry did not see that the left join looks cool I learnt something Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384137 Share on other sites More sharing options...
rocoso Posted November 3, 2007 Author Share Posted November 3, 2007 This worked! SELECT email FROM users where user_id not in (select zuserid from useralbum) gotta study SELECT within SELECT Thanks you guy are the best:) Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384314 Share on other sites More sharing options...
Barand Posted November 3, 2007 Share Posted November 3, 2007 JOINS, like Toplay used, are generally more efficient than subqueries. Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384342 Share on other sites More sharing options...
rocoso Posted November 5, 2007 Author Share Posted November 5, 2007 Thats very true! on the production server that had a older mysql version it totally bomb out. The LEFT JOIN action is the way to go... Quote Link to comment https://forums.phpfreaks.com/topic/75890-solved-mysql-query-help/#findComment-384750 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.