So I tried running this simple code
select COUNT(Ename),BOSS
from EMPLOYEE
WHERE BOSS=7839
but seems I did not get the output unless I use a "group by" boss below. I am not able to understand why can't I get output without "group by".
Can anybody explain in laymen terms. Would be much appreciated.
Count is an aggregate function. When you use Count (or any other aggregate function such as Count, Sum, Max, Min) next to select, then every other column item must be in group by. If you only use
select COUNT(Ename) -- there is no BOSS
from EMPLOYEE
then you don't have to use Group By. Lets say you have 5 columns: 1-COUNT(Ename), 2- BOSS, 3- column3, 4- column4, 5-column5. Then you would have to write select code as below:
select COUNT(Ename),BOSS, column3, column4, column5
from EMPLOYEE
WHERE BOSS=7839
GROUP BY
BOSS, column3, column4, column5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With