Jump to content

[SOLVED] Need help grouping information from three tables


zsazsageorge

Recommended Posts

Hi, I am using the MySQL Quesry Browser 5.0

 

I am trying to join information from three tables:

 

The first table is "Customers" which includes:

Customerid

Name

Address

City

 

The second table is "books," which includes:

ISBN

Author

Title

Price

 

The third table is "orders," which includes:

Orderid

Customerid

Amount

Date

 

 

I need to display a table that shows, starting from the left, the customer name, title of their purchased book, author of their purchased book.

 

So I need to somehow link the customerid with the orderid and author/title.

 

Would anyone be able to tell me how to do that?

 

Thank you so much, I am lost.

 

 

Link to comment
Share on other sites

Is there a table (something like order details) that actually shows which ISBN or book ID was purchased in a given order? Without that, it is impossible to tie the book back to the order. That has to be done in order to know who purchased each book...

Link to comment
Share on other sites

Excellent. You actually need to have all 4 tables to get your user tied to the book title and author. Run this query in MySql query browser and see what you get:

SELECT c.name, b.title, b.author 
FROM customers c
INNER JOIN orders o ON c.customerid = o.customerid
INNER JOIN order_items i ON o.orderid = i.orderid
INNER JOIN books b ON i.isbn = b.isbn

 

That should give you a list of customer names along with the author and title of the books they purchased. You may need to double check the capitalization of the tables and fields in the query as I left them all as lower case, but I hope this helps!

Link to comment
Share on other sites

One more question, if you would be so kind.

 

There is another table, called "book_reviews," which includes the following:

ISBN

Review

 

This is related to the four tables listed above.

 

How would I show for each author and title in books with its associated book review?

 

Thanks again in advance... last question I swear.

Link to comment
Share on other sites

One more question, if you would be so kind.

That's what we're here for.

 

There is another table, called "book_reviews," which includes the following:

ISBN

Review

 

This is related to the four tables listed above.

 

How would I show for each author and title in books with its associated book review?

 

You would do a similar join, but you would only have to do the join on two tables this time:

SELECT b.author, b.title, r.review
FROM books b
INNER JOIN book_reviews r ON b.isbn = r.isbn

 

Good luck!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.