Consider two table.Employee and Project.Employee table has fields like eid,ename.Project table has fields like pid,pname.Now,since an employee can work on many projects and a project can be done by many employees, therefore,as evident,there is a many to many relationship b/w the two tables.Break the many to many,and create a new table called Assignment which consists as foreign keys the eid and pid.
Here is the question, I Want to find out those employee pairs who have worked with each other in more than 1 project.For example if emp A and emp B have worked with each other on more than one project then they qualify for the above query result.
Kindly let me know what will be the query for the mentioned problem.
Here's a pretty common and straightforward solution:
This query does a join to match rows in the
Assignmenttable to other rows in the same table with the same project and a different employee. We use<to compare the employee id's so we don't get duplicate pairings.Then we use
GROUP BYto make sure there's only one row for each pair of employees.The
HAVINGclause picks only those groups that have multiple rows, which are the pairs of employees who have worked on multiple projects together.