- #1
Crystal037
- 167
- 7
- Homework Statement
- I am trying to understand how sql query selects multiple times the same value when I use a combination of condition in where.
I have 4 tables employee, project,department,works_on.
I have to find all project number that involve an employee with last name='Wong' either as a worker or as a manager of the department that controls the project.
- Relevant Equations
- select pnumber
from project,works_on,employee,department
where lname='Wong'
and ((dnum=dnumber and mgr_ssn=ssn) or (essn=ssn and pnumber=pno));
I expect output as 30,20,3,2,1 in a row but I am getting repetitions of these with 20,30 coming 3 times and 3,2 coming 18 times and 1 coming 16 times. I dont understand how combination of condition in where is leading to so many duplicates. Instead of using or if I divide the query into 2 and execute it one by one then I am getting only distinct values. Can you also explain the order by which it traverses through the table and selects tuples and display as to understand why am I getting those multiple values and why in that specific order