Buchead Posted January 15, 2008 Share Posted January 15, 2008 Hi all, I have 2 tables (staff and training), with the link between them being staffID. What I'm trying to do is pull out a list from staff which don't have any entries in training. I thought I'd have to use COUNT but can't seem to get it working. I assumed the query should mainly be: SELECT s.* FROM `staff` AS s LEFT JOIN `training` AS t ON s.staffID=t.staffID HAVING (COUNT(XX) = 0) but can't get anything working where XX is. I've tried running an inner queries comparing the 2 tables and pulling data from just 1 table. If I put in 't.staffID' where XX is it returns only the 1st entry from `staff`, despite `training` being completely empty. Also tried putting the closing bracket of the count before the '= 0' bit, and removing the brackets. Same results. There's clearly a glaring mistake somewhere but I can't see it. Please can anyone help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/86115-solved-selecting-results-from-1-table-that-dont-exist-in-another/ Share on other sites More sharing options...
fenway Posted January 15, 2008 Share Posted January 15, 2008 You don't need HAVING ... you need WHERE t.staffID IS NULL. Quote Link to comment https://forums.phpfreaks.com/topic/86115-solved-selecting-results-from-1-table-that-dont-exist-in-another/#findComment-439834 Share on other sites More sharing options...
Buchead Posted January 15, 2008 Author Share Posted January 15, 2008 Thanks. Simply assumed I needed to do a count...... Quote Link to comment https://forums.phpfreaks.com/topic/86115-solved-selecting-results-from-1-table-that-dont-exist-in-another/#findComment-439843 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.