Some clarification is needed after the discussion of DISTINCT in the class today:
1. SELECT DISTINCT A1,...,An FROM...WHERE...GROUP BY...HAVING...
results in eliminating duplicates from the result of the query
SELECT A1,...,An FROM...WHERE...GROUP BY...HAVING...
I.e., duplicate elimination is the last step in SELECT query evaluation.
2. SELECT COUNT(DISTINCT A)...eliminates duplicates from the single column A before applying COUNT (the same for other aggregate functions except COUNT(*)).
3. DISTINCT cannot be used with COUNT(*). So if one wants to count the number of distinct tuples in a relation, one needs to define a view using SELECT DISTINCT and then compute COUNT(*) over the view.
Monday, February 8, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment