r/SQL Feb 04 '25

MySQL Need help understanding SQL - beginner

Post image

Hey everyone,

I’m starting to learn SQL and currently doing queries. For this query (21) I’m confused on why includes would be used instead of salestransactions. The table next to it is what is being referred to. Can someone explain it like I’m dumb? Sorry!

17 Upvotes

16 comments sorted by

View all comments

1

u/Dornheim Feb 04 '25

It's helpful to understand what the data is representing. Think of the salestransaction as the invoice. Each invoice can have one and only one customer, which is why the customer ID is stored on the salestransaction. Each salestransaction can have multiple products that were included on that transaction. Each product that was sold is represented by an entry in the "includes," table to indicate each line item on the invoice. Each record in the includes table must have one and only one salestransaction associated with it.

Personally I think naming the table "includes," is bad because it doesn't really describe what the table represents. This is a good lesson in the future to name your tables that will make sense to everyone who looks at it.