Understanding SQL SELECT Statement

ViaByte.Net

Filtering Grouped Data with HAVING

The HAVING clause is used to filter the result set after the GROUP BY operation has been performed. It allows you to specify conditions for the grouped data. Here’s an example:

SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5;

This query will retrieve the “department” column and the count of employees in each department from the “employees” table. However, it will only include departments that have more than 5 employees.

Joining Tables

SQL allows you to combine rows from different tables using JOIN operations. There are different types of JOINs, such as INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Here’s an example of an INNER JOIN:

Bagikan:

Tinggalkan komentar