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? Databases databases sql + – shikharV asked Dec 8, 2015 shikharV 570 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
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, Tendua answered Dec 8, 2015 • edited Dec 8, 2015 by Tendua Tendua comment Share Follow See all 0 reply Please log in or register to add a comment.
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 Abbas answered Dec 8, 2015 Abbas comment Share Follow See all 0 reply Please log in or register to add a comment.