DBA > Job Interview Questions > DATABASE Administrator (DBA) Interview Questions and Answers

Diffrence between a “where” clause and a “having

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

6. Diffrence between a “where” clause and a “having” claus

Answer1
The order of the clauses in a query syntax using a GROUP BY clause is as follows:
select …where..group by…having…order by…
Where filters, group by arranges into groups, having applies based on group by clause. Having is applied with group by clause.

Answer2
In SQL Server, procedures and functions can return values. (In Oracle, procedures cannot directly return a value).
The major difference with a function is that it can be used in a value assignment. Such as:
–system function
Declare @mydate datetime
Set @mydate = getdate()

–user function (where the user has already coded the function)
Declare @My_area
Set @My_area = dbo.fn_getMy_area(15,20)

Answer3
1.”where” is used to filter records returned by “Select”
2.”where” appears before group by clause
3.In “where” we cannot use aggrigate functions like where count(*) >2 etc
4.”having” appears after group by clause
5.”having” is used to filter records returned by “Group by”<
6.In”Having” we can use aggrigate functions like where count(*) >2 etc there are two more

(Continued on next question...)

Other Job Interview Questions