Senior
Write an SQL query: select the titles of all books currently checked out by readers.
sobes.tech AI
Answer from AI
Suppose we have the following tables:
bookswith columnsbook_id,titleloanswith columnsbook_id,reader_id,return_date
To select the titles of all books currently with readers, we need to select books for which there is no return date (i.e., return_date is NULL or greater than the current date, if the planned return date is stored). Example query:
SELECT b.title
FROM books b
JOIN loans l ON b.book_id = l.book_id
WHERE l.return_date IS NULL
-- or if return_date is the return date:
-- WHERE l.return_date > CURRENT_DATE
This query will return all books that are currently not returned by readers.