SQL Having Clause, SQL Tutorial, Global Guide Line Technology.
Bookmark Bookmark: SQL Having Clause, SQL Tutorial Forum | Blog |

      Home                    

Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Create Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Having Clause.


     Back             Next     




Now SQL Tutorial will guide us that people may want to do is to limit the output based on the corresponding sum (or any other aggregate functions). e.g. we might want to see only the employees who have salary more then 1000$. Instead of using the WHERE clause in the SQL statement, though, we need to use the SQL HAVING clause, which is reserved for aggregate functions. The SQL HAVING clause is typically placed near the end of the SQL statement, and a SQL statement with the HAVING clause may or may not include the GROUP BY clause. The syntax for HAVING is,

Syntax for SQL Having Clause

SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithmetic function condition)

Note: the GROUP BY clause is optional.
In our example, table Employees_Salary.

Table Employees_Salary

FirstName Month Salary
Austin January 1000$
Creston January 1000$
Kate January 1000$
Angela January 1900$
Bobbi January 1000$
Cute January 1000$
Austin February 1100$
Creston February 1100$
Kate February 1100$
Angela February 1000$
Bobbi February 1200$
Cute February 1300$

Example of SQL Having Clause

SELECT Month, SUM(Salary)
FROM Employees_Salary
GROUP BY Month
HAVING Salary > 1000

Result of SQL Having keyword example:

Month Salary
January 1900$
February 5800$

     Back             Next     
 

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2018 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 251 visitors are online now