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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.