Given a books table containing information about books including their ratings, find all books that have not been rated yet (i.e., have a NULL rating).
The books table contains:
book_id: Unique identifier for each booktitle: Book titleauthor: Book authorpublished_year: Year the book was publishedrating: Book rating (can be NULL if not rated)
Return the result ordered by book_id in ascending order. Exclude the rating column from the output since all returned books will have NULL ratings.
Table Schema
| Column Name | Type | Description |
|---|---|---|
book_id
PK
|
int | Unique identifier for each book |
title
|
varchar | Title of the book |
author
|
varchar | Author of the book |
published_year
|
int | Year the book was published |
rating
|
decimal | Book rating, can be NULL if not rated |
Input & Output
| book_id | title | author | published_year | rating |
|---|---|---|---|---|
| 1 | The Great Gatsby | F. Scott Fitzgerald | 1925 | 4.5 |
| 2 | To Kill a Mockingbird | Harper Lee | 1960 | |
| 3 | Pride and Prejudice | Jane Austen | 1813 | 4.8 |
| 4 | The Catcher in the Rye | J.D. Salinger | 1951 | |
| 5 | Animal Farm | George Orwell | 1945 | 4.2 |
| 6 | Lord of the Flies | William Golding | 1954 |
| book_id | title | author | published_year |
|---|---|---|---|
| 2 | To Kill a Mockingbird | Harper Lee | 1960 |
| 4 | The Catcher in the Rye | J.D. Salinger | 1951 |
| 6 | Lord of the Flies | William Golding | 1954 |
The query filters books where rating IS NULL. Books with IDs 2, 4, and 6 have NULL ratings, so they are included in the result. The other books have actual rating values (4.5, 4.8, 4.2) and are excluded. Results are ordered by book_id in ascending order.
| book_id | title | author | published_year | rating |
|---|---|---|---|---|
| 1 | Book One | Author A | 2020 | 4 |
| 2 | Book Two | Author B | 2021 | 3.5 |
| book_id | title | author | published_year |
|---|
When all books have ratings (no NULL values), the query returns an empty result set since no books match the rating IS NULL condition.
| book_id | title | author | published_year | rating |
|---|---|---|---|---|
| 1 | New Book | New Author | 2023 | |
| 3 | Another Book | Another Author | 2023 |
| book_id | title | author | published_year |
|---|---|---|---|
| 1 | New Book | New Author | 2023 |
| 3 | Another Book | Another Author | 2023 |
When all books have NULL ratings, all books are returned in the result, ordered by book_id ascending.
Constraints
-
1 ≤ book_id ≤ 10000 -
titleandauthorare non-empty strings -
published_yearis a valid year -
ratingcan be NULL or a decimal value between 0.0 and 5.0