Sifer
Sifer

Reputation: 57

Advice on my relational database query

Hi I have just started using relational databases at college and I am having trouble with queries when using multiple tables. I normalized some data to the best of my knowledge as you can see below, however I am unsure how to write a query which will show me all of the products a particular customer has bought. When I have tried it just shows me all products along with that 1 customer even if they have not bought anything. Many thanks in advance!

Relationship between my tables

p.s I have looked for online documentation and vids on how to create multiple table queries but all I have found involve using one table. If anyone can point me in the direction of a good source to learn this I would appreciate it! Thanks again.

Upvotes: 1

Views: 229

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

It's only a simple inner join with the related table

select d.product_id, d.product_name
from invoce as a
inner join order as b on a.order_no = b.order_no
inner join customer as c on a.cust_no = c.cust_no
inner join product as d on b.product_id = d.product_id

Upvotes: 1

Related Questions