September 14th, 2024

Are You Qualified to Use Null in SQL?

The blog post features a quiz to test knowledge of NULL in SQL, covering various operations and complexities, and serves as an educational resource for users seeking to improve their SQL skills.

Read original articleLink Icon
Are You Qualified to Use Null in SQL?

The blog post from Project:M36 presents a quiz designed to test knowledge of using NULL in SQL. It includes various SQL queries categorized by difficulty levels, demonstrating how NULL interacts with different SQL functions and operations. The quiz covers topics such as boolean operations with NULL, aggregation functions like SUM and AVG, and the behavior of NULL in JOINs, constraints, and GROUP BY clauses. The post emphasizes the complexities and potential pitfalls of handling NULL values in SQL, highlighting that a database management system (DBMS) could theoretically be designed without NULL support. The quiz serves as an educational tool for those looking to deepen their understanding of SQL and NULL handling.

- The blog features a quiz to assess understanding of NULL in SQL.

- It includes SQL queries categorized by difficulty levels.

- The post highlights the complexities of NULL in various SQL operations.

- It suggests that a DBMS could be created without NULL support.

- The content serves as an educational resource for SQL users.

Link Icon 2 comments
By @ziml77 - 8 months
What database is this specific to? PostgreSQL?

Those first two are entirely invalid in T-SQL. Even attempting to write it as SELECT IIF(NULL AND 1=1, 1, 0) doesn't work. The AND operation can only be applied to a boolean type and the only way to get that is as the result of a comparison and it can't be stored or passed anywhere.

Also the UNIQUE constraint does not allow insert of a second NULL. I tried that both using the constraint syntax and by creating a unique index.

By @SPBS - 7 months
This is null trivia, a lot of it is not worth memorizing because it's not important. Personally I was surprised that NULL AND FALSE does not result in NULL, but who cares?