Skip to content
Advertisement

How can I get the names of authors of books with the shortest titles from this database?

Let’s suppose I have a database with the following tables

authors (author_id TEXT, name TEXT)

books (isbn TEXT, publisher TEXT, title TEXT, publication_year INTEGER)

copies (copy_id INTEGER, isbn TEXT)

authorship (isbn TEXT, author_id INTEGER)

categories (category_id INTEGER, category_name TEXT)

in_category (isbn TEXT, category_id INTEGER)

And I want to get the names of authors of books with the shortest titles. I think I could take isbn numbers of books with the shortest titles, get the author_id and from this get the name.

I would be glad for any help with this problem.

Advertisement

Answer

Where’s the problem? You already sketched the way…

SELECT
    b.title,
    a.name
FROM
    books b
JOIN authorship as ON b.isbn = as.isbn
JOIN authors a ON as.author_id = a.author_id
ORDER BY length(b.title)
LIMIT -- number of books you want
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement