I have a table in which the ids of some rows are present under another column as foreign keys. So for example if employee with id 09 served no customers, employee with id 10 served one customer and employee with id 11 served 3 customers you will have a table like this one: Id col2 col3 09 EmployeeName 2 10 EmployeeName 2 11 EmployeeName 3 13 CustomerName 11 14 CustomerName 11 15 CustomerName 10 16 CustomerName 11 Is there a way to select with a single query only the employees who haven't served any customers? In this case there is only one employee who fits this condition. My guess is that the query should select only the employees whose id isn't present in col3 but how do you do this with one query? Is this possible at all to do with a single query? How would you do it?
You're looking for 'NULL Values'. You can check out this page over at W3Schools about it (with an example): http://www.w3schools.com/sql/sql_null_values.asp Greetz!
I think I can help, but your table structure is a little sketchy and throwing me off. Specifically the values in col2--Why are their EmployeeName and CustomerName, shouldn't it all be customer names? Does the first record in your example mean employee 2 served an employee? Also, could you provide specific table and field names including the names for the table that holds all your employees?
You havent explained what column 3 holds when the entity is an employee (when its a customer column 3 is the employee's ID)
This query would be a lot easier if your data was better normalized. Then your could GROUP BY your transactions by employee_id and find which ones are zero.