//Filtering records which are not available in Project table.
SELECT a.ProjectId, b.ProjectId, b.UserId
FROM Project a
RIGHT JOIN
(
/* Here, all the projects will be linked to all the users. So, All users will be assigned to all the projects. */
SELECT DISTINCT a.ProjectId, b.UserId
FROM Project a
CROSS JOIN Users b
) b ON a.ProjectId = b.ProjectId and a.UserId = b.UserId
WHERE a.ProjectId IS NULL
ORDER BY b.ProjectId
INNER QUERY
Project.Project_Id, Project.User_id, Employee.UserId
1, 1, 1
1, 1, 2
1, 1, 3
1, 2, 1
1, 2, 2
1, 2, 3
2, 1, 1
2, 1, 2
2, 1, 3
Distinct Project.Project_Id, Employee.UserId
1, 1
1, 2
1, 3
2, 1
2, 2
2, 3
Outer query, taking records which are not available in Project table.
Please let me know for any issues
請解釋一下你的答案簡短,使之更加有用。 – 2015-03-25 07:56:39