Examveda

Usage of aggregates in WHERE clause is disallowed.

A. True

B. False

Answer: Option A

Solution (By Examveda Team)

This question asks about using aggregate functions in the WHERE clause of a MySQL query.

Aggregate functions are functions that summarize data, like SUM(), AVG(), COUNT(), MAX(), and MIN().

The WHERE clause in a MySQL query is used to filter data based on specific conditions.

The answer is True. You cannot directly use aggregate functions in the WHERE clause.

Why? Because aggregate functions operate on groups of rows, while the WHERE clause works on individual rows.

To achieve similar results, you would usually need to use a subquery or a HAVING clause.

Example:
If you want to find the customers who have placed more than 10 orders, you can't directly use COUNT(*) in the WHERE clause. You would need to use a subquery like this:
```sql SELECT customer_id, customer_name FROM customers WHERE customer_id IN ( SELECT customer_id FROM orders GROUP BY customer_id HAVING COUNT(*) > 10 ); ```

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous