Jump to content

[SOLVED] Selecting results from 1 table that don't exist in another


Buchead

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.