CompTIA Data+ (DA0-002)Data MiningEasy
A data analyst is working with a sales database that contains two tables: `Customers` (CustomerID, CustomerName, Region) and `Orders` (OrderID, CustomerID, OrderDate, OrderAmount). They need to retrieve the names of all customers who have placed an order in the 'North' region AND whose total order amount exceeds $1000. Which SQL clause is primarily used to filter rows based on conditions applied to individual rows before any grouping or aggregation?
- AGROUP BY
- BHAVING
- CORDER BY
- DWHERE
Show answer & explanationAnswer & explanation
Correct answer: D. WHERE
The WHERE clause is used to filter individual rows based on specified conditions before any grouping or aggregation takes place. In this scenario, filtering by `Region = 'North'` would be done with a WHERE clause to select only customers from that region.
Why the other options are wrong
- A. GROUP BY groups rows that have the same values in specified columns.
- B. HAVING is used to filter groups of rows after aggregation, not individual rows.
- C. ORDER BY sorts the result set, it does not filter rows.
SQL WHERE Clause
A SQL clause used to filter records from a result set based on specified conditions, applying the filter to individual rows before any grouping or aggregation.
- Filters rows based on a boolean condition.
- Can use comparison operators (`=`, `>`, `<`), logical operators (`AND`, `OR`, `NOT`), and pattern matching (`LIKE`).
- Applied before `GROUP BY` and `HAVING` clauses.
Memory trick: SQL's flow: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY.