0

I have 2 queries I have to create but they sound the same.
Note: I am just learning the theory behind SQL and not actually working on a DB at this time

Directions:
1. Show all the categories for each book with the book number, title, category number, and category name.

2. Show all the books for each category with the categbory number, category name, book number, and book title.

Tables:
Book
(book_id, book_title, publication_date, publisher_id, précis)

Category
(category_id, category_name)

Book_Category
(book_id, category_id)
FK book_id > book
FK category_id > category

This is what I got for #1:

SELECT c.category_id, c.category_name, b.book_id, b.book_title
FROM category c, book b, book_category bc
WHERE bc.book_id = b.book_id
AND bc.category_id = c.category_id
ORDER BY c.category_name, b.book_title;

After looking at #2 I am confused and I have no idea if I did this correctly.
Any help would greatly be appreciated. Thanks a bunch!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Perry31
0

Wat exactly do u want?do u want to see the result for the below statement or need to create View for the same and use select to view it?
1. Show all the categories for each book with the book number, title, category number, and category name.
2. Show all the books for each category with the categbory number, category name, book number, and book title.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.