G
G
godyesnow2017-08-19 23:37:50
JavaScript
godyesnow, 2017-08-19 23:37:50

Selection of products from the database (where the product may either have no properties, or have several of them) that satisfy several conditions?

Hello everyone) I need help in selecting products from a table by several attributes / properties, the actual database structure is as follows:
Products table - products and their general properties are stored.
attributes table - available attributes are stored.
The products_attributes table - associates products with attributes (product id, attribute id and value).
Table examples:
3ae58897dd1745088ddac19293bc9947.pngca014ad2a0df46b889a75d92e5510ef6.pnga51164e2f11c4608b7f8de67d3a5d72e.png
The question is the following, when combining all tables (to get products with their attributes), a table is expected where the number of rows of one specific product is as many as it has attributes, and if you search for a product by any one attribute, it’s clear how, then let's say we can find a product whose color is both red and blue (that is, by two attributes), I don't quite understand how!? If anyone can explain I would be grateful!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2019-04-19
@ksishka

\/\w+\/[0-9]+
There are special sites where you can "play around" with regular seasons.
For example:
https://regex101.com/r/ncxyKP/1
There is also a tutorial documentation .

D
Denis Holub, 2017-08-20
@denman1985

Through GROUP BY and HAVING.
Have a look here: How to make a filter if the relationship between a record is 1 co...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question