Introduction
What is the distinction among WHERE and HAVING clause in SQL is a standout amongst the most prominent questions during a SQL and database interviews, particularly for the beginners of the field? Since programming employments require more than one expert, it's very basic to see a couple of SQL Interview inquiries in Java and .NET meetings. Even though practically 50% of the developers say that WHERE is utilized in any SELECT query while HAVING clause is just utilized in SELECT queries, which contains total capacity or gathering by clause, which is right. Despite the fact that both the WHERE and HAVING clause is utilized to indicate a sifting condition in SQL, there are unpretentious distinctions between them. The real tough time that comes into the picture of your interview is when you are asked to clarify the result from a SELECT query, which contains both WHERE and HAVING clause. Many recruiting managers say that only 10% of the candidates can answer that. Today we shall take a deep look into Sql Having vs Where clause.
Read: How to Prevent SQL Injection Attacks?
Difference between Having and Where in SQL
SQL is the Structured Query Language that is comprehensive or declarative in nature and used to access data from databases. In SQL and database interview questions, one of the most asked questions by beginners is how Where and Having clauses are different in SQL. Since programming language usually needs more than one skill, it is common to evaluate the database knowledge of a candidate in Java or the .Net interviews too. Many Java programmers or .NET developers are not supposed to have the SQL knowledge, fail to answer this question. However, most programmers think that where clause is used in any SELECT query while Having clause is only used in SELECT queries that contain aggregate functions or Group by clause too. Though both Where and Having clauses are used to specify the filter conditions in SQL, there is a significant difference between Having and Where clause in SQL.
Learn SQL Server in the Easiest Way
- Learn from the videos
- Learn anytime anywhere
- Pocket-friendly mode of learning
- Complimentary eBook available

Read: SQL Schema | Learn How to Create, Alter and Drop Schema in SQL Effectively!
Comparison chart - Difference Between Where and Having Clause
| Comparison Parameters | Where Clause | Having Clause |
| Implementation | This clause is implemented in row operations. | This clause is implemented in column operations. |
| Application | This clause is applied to a single row. | This clause is applied to summarized rows or groups. |
| Data extraction | It fetches the selected data from the table based on the condition. | Complete data is fetched together and separated based on condition later. |
| Aggregate Functions | These functions don’t appear in Where clause. | These functions can appear in Having clause. |
| Used along | It can be used with SELECT and other statements like Update, Insert, Delete etc. | It cannot be used without a SELECT query. |
| Acts as | It acts as the pre-filter. | It acts as the post-filter. |
| Group By | Group by clause comes after Where. | Group by clause comes after Having. |
What is Where Clause in SQL?
The SQL where clause is used to describe the condition at the time of data retrieval from a single table or by combining multiple tables together. It helps to return a value from the table once the condition is fulfilled. Hence, the Where clause retrieves needed parameters only and rest other parameters are violated. SQL also used logical conditions with Where clause like “and”, “OR” etc that are known as Boolean conditions too. If the condition sets true then tuples are retrieved quickly, if the condition is set false then it will retrieve any tuples. The logic expression involves comparison operator too such as <, <=, >, >=, =, and <>. These comparison parameters are used to compare strings or arithmetic expressions. They are frequently used with SELECT statements and other similar statements like Update, Delete, etc. Let us understand this clause with the help of an example. There is one Sales Table below that consists of the Product name and Sales amount attributes. tributes.
The following query can be used to calculate the total sales of phones and speakers.
The final output can be given as below.
This is the resulting output where rows are filtered first, phone and speaker rows are filtered then the aggregate function is performed.
Read: How to Download and Install Microsoft SQL Server Data Tools?
What is a Having Clause in SQL?
The having clause in SQL can be in conjunction with Group By clause. Having Clause helps to retrieve the values of groups that fulfill certain conditions. The Where clause is generally used in conjunction with Having clause. Where clause will filter individual row and Having clause will filter summarized data or grouped data.
SQL Server Training & Certification
- No cost for a Demo Class
- Industry Expert as your Trainer
- Available as per your schedule
- Customer Support Available

The output is the same where products are retrieved first then the aggregate function is performed and groups are filtered in the end unlike Where clause.
If we want to filter only those products where the total sale is greater than 1000 then the query can be written as below.
The final output, in this case, would be:
We cannot find this result using Where clause in spite of having and it generates an error message because Where clause cannot be used with aggregate functions.
Read: Online SQL Queries for Practice Questions with Answers
What are the Key Difference between Where and Having Clause in SQL?
- Where clause is used in row operations and it is generally applied on a single row only whereas Having clause is used in column operations and it is generally applied on summarized data and groups.
- In where clause, the desired data is fetched according to the applied condition. In contrast, having clause fetches the whole data then separation is made based on the condition.
- Aggregate functions like min, max, avg, sum, the count can never appear with Where clause while all of these can be used along Having Clause.
- We cannot use the Having Clause without a SELECT statement. Conversely, we can use Where clause with SELECT, Update or Delete statements.
- Where clause usually behaves as the pre-filter while having clause behaves like a post-filter.
- Where clause can be used with Group by the statement and it comes before Group by clause. It signifies that Where clause filters the rows before aggregate calculations are performed. At the same time, having Clause comes before Group by a clause that means it filters data after aggregate functions are performed.
- Key point, which is additionally the primary contrast between the WHERE and HAVE clause in SQL is that condition indicated in WHERE statement is utilized while getting information (lines) from table, and information which doesn't pass the condition won't be passed into the result set, then again HAVE clause is later used to channel the abridged data or gathered data.
- In short if both the WHERE and HAVING Clause are utilized in a SELECT query with total capacity or GROUP BY clause, it will execute before the HAVING clause.
- Where clause can be connected to a solitary row, whereas the Having clause is connected to the entire group. However, it doesn't imply that we can't have both Where and Having clauses in a single query. In the event that both where and Having statements are utilized together in single query, where clause will apply the filter condition to the list of the records, and it will channel the gathering of records from the table and Have clause will be connected to this resultant gathering and other gatherings which meets the condition given in a having statement. It will be separated in the resultant table.
- One syntax level contrast among WHERE and HAVING statement is that, the former one is utilized before the GROUP BY clause, while the latter one is utilized after the GROUP BY clause.
- When the WHERE and HAVING Clause is utilized together in a SELECT query with a total capacity, WHERE clause is connected first on individual rows and just rows that pass the condition is incorporated for making gatherings. When the group is made, the HAVING clause is utilized to channel groups dependent on the condition which has been determined already by the database administrator.
SQL Server Training & Certification
- Personalized Free Consultation
- Access to Our Learning Management System
- Access to Our Course Curriculum
- Be a Part of Our Free Demo Class

Conclusion:
This is pretty much it. I am sure if you read this blog before your interview, you will ace that one question which is the favorite of the interviewers. It has become very important for you to learn about the various joins and there differences. According to Google ‘having vs where SQL’ is one of the most searched items in SQL server domain , join an online learning platform and grab a great job. Good Luck!
Read: Learn How to Add Column Using SQL Server ALTER TABLE ADD Column Statement