Home > Articles > Data > SQL

  • Print
  • + Share This
This chapter is from the book

10.5 Grouping of NULL Values

If grouping is required on a column that contains NULL values, all these NULL values form one group. When rows are grouped, NULL values are also considered to be equal. The reason is that, with a GROUP BY, a vertical comparison is applied. This is in accordance with the rules described in Section 9.5, in Chapter 9, "SELECT Statement: SELECT Clause and Aggregation Functions."

Example 10.10. Find the different league numbers.

SELECT   LEAGUENO
FROM     PLAYERS
GROUP BY LEAGUENO

The result is:

LEAGUENO
--------
1124
1319
1608
2411
2513
2983
6409
6524
7060
8467
?

Explanation: Players 7, 28, 39, and 95 do not have a league number and, therefore, form one group (the last row) in the end result.

  • + Share This
  • 🔖 Save To Your Account