edited by
601 views
0 votes
0 votes

Consider the following relational schema :

    Employee ( Empid, Deptid, Salary )

    Department ( Deptid, DeptName )

 

What does the following query return ?

Query_1 :-

     Select D.DeptName

     From Department D

     Where ( Select COUNT(*)

                  From Employee E

                  where E.Deptid = D.Deptid and E.Salary > 1000 )   >  2

Query_2 :-

    Select min( Depatment.DeptName ) as deptname

    From Department inner join Employee on Department.Deptid = Employee.DeptId

    Where Salary > 1000

    Group By ( Empid ) 

    Having count( EmpId )  ≥ 2

 

are  both the query  return same output ??

in second query what is mean by min(dept.name ) is it count having minimum dept name ?

edited by

1 Answer

2 votes
2 votes

are  both the query  return same output ??

No...

i) Aggregate operators produce single output, but your Query_1 may result more than one

ii) Actually Query_2 is wrong due to Aggregate operators use column, then that column should be used in GROUP BY clause or that column should be key.

 

in second query what is mean by min(dept.name )

when you use min on column, then output should be select minimum value from that column..

if it is used on the VarChar datastructure, then arrange them in Alphabetical order, pick up the least one

i mean APPLE, BALL ==> APPLE is the MINIMUM

 

Now, My Question is what are the changes necessary to do for Query_2 to match it with Query_1 ?

 

Query_1 :-

     Select D.DeptName

     From Department D

     Where ( Select COUNT(*)

                  From Employee E

                  where E.Deptid = D.Deptid and E.Salary > 1000 )   >  2

Query_2 :-

    Select Depatment.DeptName

    From Department inner join Employee on Department.Deptid = Employee.DeptId

    Where Salary > 1000

    Group By ( Deptid

    Having count( Deptid > 2

 

Note that After grouping by Deptid, Deptid is the key for resultant table

==> No problem by using select Department.DeptName statement

Related questions

1 votes
1 votes
1 answer
1
Shubhanshu asked Dec 24, 2018
1,322 views
According to me it should be – “Retrieve the names of all students with a lower rank, than all students with age < 18 ”
0 votes
0 votes
1 answer
2
Shivani gaikawad asked Nov 3, 2018
679 views
i don't know the actual answer for the questionaccording to me answer should be A please confirm it
0 votes
0 votes
0 answers
3
Tuhin Dutta asked Dec 15, 2017
413 views
Student tableROLLNONAMEMARKS1MARKS21T50302S70993DNULL10NULLNULL78NULLNULLNULLNULLNULLa) select count(MARKS1) from student;b) select count(*) from student;
0 votes
0 votes
0 answers
4