As documented in the MySQL Reference Manual:
a UNIQUE index permits multiple NULL values for columns that can contain NULL.
There are many scenarios in which this behavior is desirable. For
example imagine you create a user table and require an email
address, but you want username to be optional. You make the
username column nullable, but you also want to make sure all
non-null values in the column are unique, so it makes sense to
add a UNIQUE INDEX. If the UNIQUE INDEX
didn't allow multiple NULL values then you would
need to move the username column to a separate table in order to
both maintain uniqueness and allow users without usernames.
But there are also plenty of scenarios where this behavior can cause problems. For example, consider aggregated …
[Read more]