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...

This chapter mentions that it does not matter whether 0 represents present or absent. Explain in detail why this is the case.

What will be an ideal response?

Computer Science & Information Technology

Which of the following cannot cause a syntax error to be reported by the Java compiler?

a. Mismatched {} b. Missing */ in a comment that begins with /* c. Missing ; d. An extra blank line.

Computer Science & Information Technology

Discuss a situation in which it would be more appropriate to use a do…while statement than a while statement. Explain why.

What will be an ideal response?

Computer Science & Information Technology

If you know exactly how many rows and columns you want to create, you can click the Table button in the Tables group on the Insert tab, and then click ____ on the menu.

A. Insert Rows and Columns B. Add Table C. Insert Table D. none of the above

Computer Science & Information Technology