need some help with sql stuff. Look down below for my sql code snippet.
create table product
(
id int auto_increment primary key,
title text null,
stock int default 0 not null,
price float(9,2) default 0.00 not null
);
create table product_property_value
(
id int auto_increment primary key,
product_id int not null,
property_id int not null,
value varchar(255) null
);
create table property
(
id int auto_increment primary key,
code varchar(20) null,
title varchar(50) null
);
I have a statement for select all rows from these three tables with pretty output.
SELECT
title,
stock,
price,
(
SELECT GROUP_CONCAT(p.title, ': ', pv.value SEPARATOR ', ')
FROM product_property_value pv
INNER JOIN property p on pv.property_id = p.id WHERE pv.product_id = product.id
) property_values
FROM product;
My property table is filled with this data:
insert into property (id, code, title) values (1, 'color', 'Color');
insert into property (id, code, title) values (2, 'width', 'Width');
insert into property (id, code, title) values (3, 'height', 'Height');
My product_property_value table is filled with this data (there is one example for one product, table have many of it):
insert into product_property_value (id, product_id, property_id, value) values (4, 2, 1, 'Green');
insert into product_property_value (id, product_id, property_id, value) values (5, 2, 2, 4);
insert into product_property_value (id, product_id, property_id, value) values (6, 2, 3, 4);
So the main question is how to select products only with specified values: Select products with color = "Red", width=4 or width=5 and height = 5. I need to modify statement or change it but anyway i need to save prettified output. Feel free to answer, thanks.