Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 show all categories

Author  Topic 

gorlock27
Starting Member

3 Posts

Posted - 2011-02-24 : 16:13:33
i need to show all the categories for each book. is there a command that allows you to display multiple categories(category_name)?

CREATE VIEW book_category AS
SELECT book_id, book_title, category_id, category_name
FROM category, book, book_category
WHERE category.category_id = book_category.category_id
AND book_category.book_id = book.book_id
ORDER BY book.book_id;

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-02-24 : 18:43:46
Not sure what you mean. Your query will show all category_names that have a matching id in the book and book_category tables

Jim

CREATE VIEW book_category AS
SELECT b.book_id, b.book_title, c.category_id, c.category_name
FROM book b
INNER JOIN book_category bcat ON
b.book_id = bc.book_id
INNER JOIN category c ON
c.category_id = bc.category_id

ORDER BY b.book_id;

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-02-26 : 09:31:27
probably you can show some sample data and explain what you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -