Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- books (book_id INT PRIMARY KEY, book_title VARCHAR)
- authors (author_id INT PRIMARY KEY, author_name VARCHAR)
- subjects (subject_id INT PRIMARY KEY, subject_name VARCHAR)
- book_authors (book_id INT, author_id INT)
- book_subjects (book_id INT, subject_id INT)
- SELECT books.book_id, books.book_title,
- 'author' as record_type, authors.author_name as record_value
- LEFT JOIN book_authors ON books.book_id = book_authors.book_id
- LEFT JOIN authors ON authors.item_id = book_authors.author_id
- UNION
- SELECT books.book_id, books.book_title,
- 'subject' as record_type, subjects.subject_name as record_value
- LEFT JOIN book_subjects ON books.book_id = book_subjects.book_id
- LEFT JOIN subjects ON subjects.subject_id = book_subjects.subject_id;
Add Comment
Please, Sign In to add comment