In applications that cannot tolerate duplicates it may be necessary to use DISTINCT. However, the query plan needed to support DISTINCT requires a sort, which is expensive. Therefore you should only use DISTINCT when duplicates are possible in the result set. Using the schema of Section 4.8, check the following queries to see if duplicates are possible. Explain your answer in each case.

a.
```
SELECT S.Name
FROM Student S
WHERE S.Id LIKE ’1’
```

b. ```
SELECT S.Id
FROM Student S, Facu lty F
WHERE S.Address = F.Address
```

c. ```
SELECT C.CrsCode, COUNT(*)
FROM Transcript T
GROUP BY T.CrsCode
```

d. ```
SELECT F.Name, F.DeptId, C.ClassTime, C.CrsCode,
C.Semester, C.Year
FROM Facu lty, Class C
WHERE F.Id = C.InstructorId
```

e. ```
SELECT S.Name, F.Name, T.Semester, T.Year
FROM Facu lty, Class C, Transcript T, Student S
WHERE F.Id = C.InstructorId AND S.Id = T.StudId AND
C.CrsCode = T.CrsCode AND
C.SectionNo = T.SectNo AND
C.Year = T.Year AND C.Semester = T.Semester
```

a. Duplicates are possible since students with di?erent Ids might have the same name
b. Since Address is not a key of Faculty, there may be several rows of Faculty that match a row of Student. Hence duplicates are possible.
c. No duplicate possible since all rows of Transcript with a particular value of CrsCode are grouped into a unique row in the result set.
d. Since a professor can teach only one class at a particular time there can be no duplicates
e. Duplicates are possible since a student may be taught by a professor in two di?erent courses in the same semester.

Computer Science & Information Technology

You might also like to view...

A primary key field and the corresponding foreign key field must have the same field name.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What would be displayed as a result of executing the following code?

int x = 15, y = 20, z = 32; x += 12; y /= 6; z -= 14; System.out.println("x = " + x + ", y = " + y + ", z = " + z); a. x = 27, y = 3.333, z = 18 b. x = 27, y = 2, z = 18 c. x = 37, y = -14, z = 4 d. x = 27, y = 3, z = 18

Computer Science & Information Technology