9
Reply

What is the difference between where clause and having Clause?

Vsd Vsd

Vsd Vsd

8y
1k
0
Reply

    Where Clause: 1.Where Clause can be used other than Select statement also 2.Where applies to each and single row 3.In where clause the data that fetched from memory according to condition 4.Where is used before GROUP BY clause Ex:Using Condition for the data in the memory.Having Clause: 1.Having is used only with the SELECT statement. 2.Having applies to summarized rows (summarized with GROUP BY) 3.In having the completed data firstly fetched and then separated according to condition. 4.HAVING clause is used to impose condition on GROUP Function and is used after GROUP BY clause in the query Ex: when using the avg function and then filter the data like ava(Sales)>0

    Where clause filter data before grouping where as Having clause filter after grouping.We can't use aggregate functions with where clause but we can use it with having clause.

    Where clause is used in simple select statement to filter data; whereas having clause is used to filter data obtained from grouping function output.

    The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. The difference between the two is in the relationship to the GROUP BY clause: WHERE comes before GROUP BY; SQL evaluates the WHERE clause before it groups records

    Where executes before query Having executes after query

    Where executes before query & having executes after query execution

    Having Keyword is used in GROUP BY clause only while Where keyword can be used according our necessary but in Group By Condition where clause can used before GROUP BY Clause for ex. select name,sum(marks) from student_details where marks>=50 group by name having marks 60 Here student_details is table which contains student's marks with name.

    WHERE clause filters rows from the final result and HAVING clause is used with GROUP BY clause and filters groups from the final result

    having clause is used with group by function whereas where may or may not use with group by clause