I have a table which stores all item information and its id. Now I want to create an table with all customers and log which item who bought. What is the best solution for this? I guess it is not very efficient if store it like this:
|customer_id | username | password | boughtproducts |
| 1 | herbert |123 |productid1,pid2...|
How would you do it?
A simpler way to deal with this situation is the following:
Table Customer:
customer_id | username | password
Table Product:
product_id | productName | …
Table Sales:
sale_id | customer_id | product_id | Time of sale
This way, using the table ‘Sales’, you will store all the sales of every customer and product.
The customer_id in ‘Sales’ is a foreign key from ‘Customer’ table, and product_id in ‘Sales’ is a foreign key from ‘Product’ table.
I hope this answered your question