0

I have a relational schema as follows:

INVENTORY(inventoryID,title,wholesale,markup,qtyinStock,discount) Primary-Key: inventoryID BOOK(coverType,inventoryID) Primary-Key: inventoryID Foreign-Key: inventoryID DVD(classification,ReleaseYear,StarRating) Primary-Key: inventoryID Foreign-Key: inventoryID 

BOOK and DVD are basically the subtypes of Inventory. They are inheriting from INVENTORY. Now, I want to display all the items in the inventory as either a book or a DVD depending upon the items presence in the table. I did the following but I am not sure if this is right:

SELECT title FROM INVENTORY,BOOK,DVD WHERE INVENTORY.inventoryID = BOOK.inventoryID AND INVENTORY.inventoryID = DVD.inventoryID 

This doesn't display the titles of the items though. How can I add that? Thanks!

2 Answers 2

1

Unless I read your question incorrectly the query is simple. Your example query pulls inventory that is both a DVD and Book.

SELECT title, CASE WHEN b.inventoryID IS NOT NULL THEN 'Book' WHEN d.inventoryID IS NOT NULL THEN 'DVD' END AS Category FROM Inventory i JOIN Book b on i.inventoryID = b.inventoryID JOIN DVD d on d.inventoryID = i.InventoryID 
Sign up to request clarification or add additional context in comments.

2 Comments

,So, I want to display whether an item in the inventory is a book or a DVD. I think your query just displays the title. That's it. I want to display the category as well (DVD/Book).
@HarryLewis I updated the answer. I only pulled the title because that is what you were pulling in your original example.
0

With the AND in the WHERE clause you are trying to get the title of the inventory item that is both book AND dvd. Try changing the AND for and OR

1 Comment

So, I want to display whether an item in the inventory is a book or a DVD. I think your suggestion just displays the title. That's it. I want to display the category as well (DVD/Book).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.