Database Management Exam  >  Database Management Videos  >  SQL Server Administration: Basic Tutorials  >  Difference between where and having in sql server

Difference between where and having in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

148 videos

FAQs on Difference between where and having in sql server Video Lecture - SQL Server Administration: Basic Tutorials - Database Management

1. What is the difference between the WHERE and HAVING clauses in SQL Server?
Ans. The WHERE clause is used to filter rows based on a condition before the data is grouped or aggregated. It is used with the SELECT, UPDATE, and DELETE statements. On the other hand, the HAVING clause is used to filter rows based on a condition after the data has been grouped or aggregated. It is used with the SELECT statement along with the GROUP BY clause.
2. Can the WHERE clause be used with the GROUP BY clause in SQL Server?
Ans. Yes, the WHERE clause can be used with the GROUP BY clause in SQL Server. The WHERE clause is used to filter rows before they are grouped, while the GROUP BY clause is used to group rows based on one or more columns. Both clauses can be used together to perform more specific filtering and grouping operations.
3. When should I use the WHERE clause and when should I use the HAVING clause in SQL Server?
Ans. The WHERE clause should be used to filter rows based on a condition before grouping or aggregating data. It is used to filter individual rows. On the other hand, the HAVING clause should be used to filter grouped or aggregated data. It is used to filter groups of rows. In general, use the WHERE clause to filter individual rows and the HAVING clause to filter grouped or aggregated data.
4. Can I use aggregate functions in the WHERE clause in SQL Server?
Ans. No, you cannot use aggregate functions in the WHERE clause in SQL Server. The WHERE clause is used to filter individual rows based on a condition, and aggregate functions operate on multiple rows to return a single value. If you need to filter rows based on aggregated data, you should use the HAVING clause instead.
5. Is the order of the WHERE and HAVING clauses important in SQL Server?
Ans. Yes, the order of the WHERE and HAVING clauses is important in SQL Server. The WHERE clause is evaluated before the data is grouped or aggregated, while the HAVING clause is evaluated after the data has been grouped or aggregated. Therefore, the WHERE clause should be used to filter rows before grouping or aggregating, and the HAVING clause should be used to filter grouped or aggregated data.
Explore Courses for Database Management exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Difference between where and having in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

Important questions

,

Viva Questions

,

study material

,

practice quizzes

,

mock tests for examination

,

Objective type Questions

,

Free

,

Summary

,

shortcuts and tricks

,

Difference between where and having in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

Sample Paper

,

pdf

,

video lectures

,

ppt

,

Semester Notes

,

Exam

,

past year papers

,

Extra Questions

,

Difference between where and having in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

MCQs

,

Previous Year Questions with Solutions

;