A
A
Alex-19172018-09-17 13:11:52
MySQL
Alex-1917, 2018-09-17 13:11:52

How to organize the storage and quick selection of two fields from the database?

I came across a shop on self-writing, where the Product is a few photos, a price, a description, and actually everything)))
I want to refine it to the level - the product has a size and color, the price of the product is linked to a combination of these two parameters and plus attributes (fabric brand, fabric composition , storage conditions, etc.), they do not affect the price.
Those. example:
Men's shirt art.21970 blue 50r-r - price 340r
Men's shirt art.21970 blue 52r-r - price 360r
Men's shirt art.21970 yellow 50r-r - price 330r
Men's shirt art.21970 yellow 52r-r - price 370r

There is already a table product id,name,category_id,price....
How best to store two properties - size and color?
I see two options -
1. Each property has its own table plus a combination table - it is convenient to select with a flat query when selecting a list of products, it is inconvenient to import products.
2. Both properties in one table - it's convenient to import-fill, but the selection turns into a bunch of joins and groupings...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alex-1917, 2018-09-18
@alex-1917

I did this:
a piece from the database
in the admin panel:
5ba1541d90d18975833755.png

R
Ruslan., 2018-09-17
@LaRN

If in the future you want to expand the set of attributes, then in the case of a separate table with attributes, this will be easier to do. Again, to search by color / size for any other attribute, the queries will be the same, you won't have to rewrite the store engine for each new parameter.
Well, from the point of view of disk saving: it may turn out that one product will have one set of attributes, and another another, but in the database (if they are added to the table with products) they will still take up space (even though they will conditionally zero)

A
Antonio Solo, 2018-09-17
@solotony

if there are few attributes and their number is known -
for the names of the attributes themselves -
store your product tables all in one table, attribute id - foreign keys. and you will be happy.
although in your case one table will do (in the sense of one in general)
and the option of storing different properties in one table is when the number of properties is variable, it is unknown, different objects have different properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question