From the course: Quick Start Guide to SQL
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Filtering group results
From the course: Quick Start Guide to SQL
Filtering group results
- [Instructor] Let's learn how to restrict groups and display only those group results that are needed. We cannot give GROUP_FUNCTIONS in the Where condition, it'll throw an error. So instead of giving the group_condition in the Where, we use another clause that is the Having clause. This is the syntax for it. SELECT, column names, if there are any GROUP_FUNCTIONS we give them here, FROM table_name, WHERE condition, then GROUP BY any group_by_expressions, followed by HAVING group_conditions. This is where we will give any conditions related to GROUP_FUNTIONS. And, finally, ORDER BY clause to sort defiltered data. Let's take an example for this. So, now, if I want to display only highest salaries in all departments that are greater than 4,000. If I try to give something like this, SELECT deptno,MAX salary FROM emp_tab WHERE MAX of salary >= 4000 GROUP BY deptno; I have given the GROUP_FUNCTION here in the WHERE…
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.