. Which of the following is not a valid aggregate function?
a. COUNT
b. COMPUTE
c. SUM
d. MAX
To eliminate duplicates from a query result we use:
a. Unique
b. Distinct
c. *
d. where
The Correct Answer and Explanation is:
Correct Answers:
- Which of the following is not a valid aggregate function?
Answer: b. COMPUTE - To eliminate duplicates from a query result we use:
Answer: b. Distinct
Detailed Explanation (300+ words):
1. Aggregate Functions in SQL:
Aggregate functions in SQL are used to perform calculations on a set of values and return a single value. These are commonly used in conjunction with the GROUP BY clause to summarize data. Examples of valid aggregate functions include:
The option COMPUTE is not a valid aggregate function. While the word “compute” might sound like it performs a calculation, it is not an SQL aggregate function recognized by standard SQL syntax. In some older versions of SQL Server, COMPUTE was a keyword used to display summary values, but it has been deprecated and is not considered an aggregate function itself. Therefore, the correct answer is b. COMPUTE.
2. Removing Duplicates in SQL:
When retrieving data from a database using SQL, you might encounter duplicate rows. To ensure that only unique rows are returned, the DISTINCT keyword is used in the SELECT statement. For example:
SELECT DISTINCT city FROM customers;
This query returns a list of unique cities from the customers table, eliminating any duplicate entries.
Let’s evaluate the options:
- a. Unique: This is not valid SQL syntax. Although some databases use “UNIQUE” as a constraint, it is not used in the
SELECTstatement to eliminate duplicates. - b. Distinct: This is the correct keyword used to remove duplicate records from the result set.
- c. *: This symbol selects all columns from a table but does not eliminate duplicates.
- d. Where: This is used to filter records based on conditions but does not remove duplicates.
Therefore, to eliminate duplicate rows from a query result, the correct answer is b. Distinct.
Summary:
COMPUTEis not a valid aggregate function.