From the course: Advanced SQL: Logical Query Processing, Part 1
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Group filters - SQL Tutorial
From the course: Advanced SQL: Logical Query Processing, Part 1
Group filters
- [Instructor] After the GROUP BY had its way, the group set is passed on to the HAVING clause. HAVING is very similar to the WHERE clause in the sense that both consist of logical predicates, and both discard elements for which the predicate does not evaluate to true. The difference between WHERE and HAVING is their location in query processing order. When they take place, and consequently the type of elements they can filter. The WHERE filter was applied right after the FROM clause, so is only had access to the source rows. The HAVING clause is processed after the GROUP BY, so it can no longer refer to individual rows, only to row groups. So HAVING can use aggregate functions for its predicate, something we couldn't do in the WHERE clause before the groups were formed. A row group, for which the HAVING predicate does not evaluate to true, will be discarded. A less known fact is that we can use non-aggregate expressions…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.