570 views
0 votes
0 votes
A B C
5 2 1
10 NULL 2
15 2 3

In the above relation T the output of query:

select * from T group by B;
A B C
10 NULL 2
5 2 1

Can anyone explain why this is the output?

2 Answers

Best answer
5 votes
5 votes
The group by command just return each row for unique combination of group by attributes. And every null is calculated as a unique group . i.e. if u have one more row then with NULL u will gate 3 rows. because the both the null will be calculated as a different group.
and it is not always the case it will return the first row. i think it is dependent on the database software . like on mysql i got first row, while on the online sql ide . http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
this will produce the last row,
edited by
3 votes
3 votes
Remember one thing when you do group by clause then it will select the first row of each group so you are getting this answer

Related questions

2 votes
2 votes
1 answer
1
Parshu gate asked Nov 6, 2017
4,010 views
2 votes
2 votes
2 answers
2
Tendua asked Dec 4, 2015
845 views
How does group by works. ya it make groups of the data . and what i know it will group the data. what what i found on running on the online tutorials is that , the group ...
0 votes
0 votes
0 answers
3
vishal burnwal asked Aug 22, 2018
764 views
If aggregate functions are used in the select clause along with attribute list we must use group by clause for grouping the attribute values ?SELECT a1, COUNT(*) FROM Emp...