+ 2

What is the difference between Having and Where clause?

2nd Feb 2018, 5:43 PM
Dinesh Reddy Chinakampalle
Dinesh Reddy Chinakampalle - avatar
2 Answers
+ 2
where clause is used to filter out table rows to be queried based some conditions. Having clause is used when you use a group by some field, and you want filter the groups based on some criteria. Let us take an example of student marks table which contains the following columns. student ID, subject id, marks and you want to filter the students whose total marks are greater than 300, you would write a query like this. select student_id, sum(marks) from marks group by student_id having sum(marks) > 300
2nd Feb 2018, 7:31 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 1
Thanks Ravi
2nd Feb 2018, 8:02 PM
Dinesh Reddy Chinakampalle
Dinesh Reddy Chinakampalle - avatar