Home > Database > Mysql Tutorial > body text

The difference between Where and Having clauses in SQL

WBOY
Release: 2023-08-21 14:53:02
forward
1532 people have browsed it

The difference between Where and Having clauses in SQL

In this article, we will understand the difference between WHERE clause and HAVING clause in SQL.

WHERE clause

  • It is used to filter records from the table based on specific conditions.

  • It can be used without the "GROUP BY" clause.

  • It can be used with row operations.

  • It cannot contain aggregate functions.

  • It can be used with "SELECT", "UPDATE" and "DELETE" statements.

  • If required, it can be used before the "GROUP BY" clause.

  • It is used with single-line functions (such as "UPPER", "LOWER").

HAVING clause

  • It is used to filter records from groups based on specific criteria.

  • It cannot be used without the "GROUP BY" clause.

  • It is used with column operations.

  • It can contain aggregate functions.

  • It can only be used with the "SELECT" statement.

  • It is used after the "GROUP BY" clause.

  • It can be used with multi-line functions (such as "SUM", "COUNT").

The following is the syntax:

SELECT column1, column2
FROM table1, table2
WHERE [ conditions ]
GROUP BY column1, column2
HAVING [ conditions ]
ORDER BY column1, column2
Copy after login

The above is the detailed content of The difference between Where and Having clauses in SQL. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template