Home  >  Article  >  Database  >  The difference between Where and Having clauses in SQL

The difference between Where and Having clauses in SQL

WBOY
WBOYforward
2023-08-21 14:53:021516browse

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete