I have a sales database where I want to get customer details based on these categories selection. I have around 15 categories and my customer database is 5 million records. Each product may fall under more than one category. I need to retrieve customer name based on the category selected. Is it a better approach to put all these categories as columns or create separate table for product and category and then inner join? I want in terms of performance which one is a better approach.
Approach 1:
here 1 says that the product is under that category.
Approach 2:
Second Approach (Approach 2
) is much better solution rather than creating single table because it is not necessary that every product may have all categories in approach one you are reserving space by creating separate columns even though category exist or not, and what if in future if one category is increased you will have to alter the current structure of the table and it will be tough task.
Yes Join will be bit slow but if you create index properly it will perform much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With