Friday, March 23, 2012

Many-To-Many

I have tried this post in the PostgreSQL, but it is probably more specific to this forum. Sorry for any duplicates.

I have two tables one is a tasks table and the other an employees table. A third table I have is called participants. This third table holds the IDs of tasks and the IDs of employees assigned to complete those tasks. My problem is figuring out how to select employee IDs and names from the employees table that are not associated with a specific taskid in the participants table.
My first attampt was:
SELECT Employees.employeeid,Employees.username FROM Employees,Participants WHERE Participants.taskid=# AND Employees.employeeid!=Participants.employeeid.

#=any valid integer id in the taskid field of the Participants table.

This attempt just gave me everyone in the Employees table.

A more graphical representation of the tables:
tasks
-taskid
-task_name
-due_date
-assignment_date

employees
-employeeid
-first_name
-last_name

participants
-participantid
-taskid
-employeeid

Thanks for any input.Select *
from tableA
where id NOT IN
(Select id from tableB)sql

No comments:

Post a Comment