Watch Our YouTube Channel
It is currently Tue Jan 23, 2018 1:55 am
 

All times are UTC



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Dec 08, 2016 8:46 am 
Offline

Joined: Fri Nov 13, 2015 3:56 am
Posts: 460
In short if both WHERE and HAVING clause is used in a SELECT query with aggregate function or GROUP BY clause, it will execute before HAVING clause.

WHERE clause is used for filtering rows and it applies on each and every row, while HAVING clause is used to filter groups in SQL.

The WHERE clause specifies the criteria which individual records must meet to be selected by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.

The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.

The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.

The WHERE clause can be used any type of sql statements but The HAVING clause can be used with only group functions.

Example:
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value;

_________________
Learn Web Development | Latest Technology News |Motivational Quotes


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 13, 2016 12:37 pm 
Offline

Joined: Wed Jul 01, 2015 11:28 am
Posts: 172
Location: Bangalore
One syntax level difference between WHERE and HAVING clause is that, former is used before GROUP BY clause, while later is used after GROUP BY clause.

_________________
Digital Marketing Company in India| Web Design Company in India | SEO Services in India


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron