schilly Posted January 20, 2010 Share Posted January 20, 2010 I have a users and orders table. Both share the username field. I need to find all users who have no orders associated with their account. I'm pretty sure it needs a join but I don't have much practise with them so some help is needed. I'm guessing something like: select * from users INNER JOIN orders ON users.username = orders.username where (SELECT sum(id) FROM orders WHERE users.username = orders.username) = 0 I'm not getting any errors but also getting no results. Thx. Quote Link to comment https://forums.phpfreaks.com/topic/189101-join-help/ Share on other sites More sharing options...
fenway Posted January 20, 2010 Share Posted January 20, 2010 You need a LEFT JOIN... IS NULL query. Quote Link to comment https://forums.phpfreaks.com/topic/189101-join-help/#findComment-998455 Share on other sites More sharing options...
schilly Posted January 20, 2010 Author Share Posted January 20, 2010 awesome. thanks so much. worked perfect. for the record, here's what I changed to: select * from users LEFT JOIN orders ON users.username = orders.username where (SELECT sum(id) FROM orders WHERE users.username = orders.username) IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/189101-join-help/#findComment-998769 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.