Consider a relation table (Balance,Customer) with the following records:

Now I tried these two queries here:
-- Query 1:
select A.Customer, count(B.Customer)
from account A, account B
where A.balance < B.balance
group by A.Customer;
-- Query 2:
select A.Customer, count(B.Customer)
from account A, account B
where A.balance < B.balance;
The first query gives me no output. With the second query, I am getting an output with count = 0.
In both cases there are no rows satisfying the criteria in the where clause, and hence no rows are returned. Then why is the count function giving an output only in the second case?
An aggregation query that has no group by always returns one row (if it is syntactically correct). The count in such a row would be 0.
An aggregation query with a group by returns one row per group. If there are no groups then there are no rows.
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