I want to retrieve multiple rows using same id's. Therefore having this table "component_property", I would like to have as results 2 records, id's: 8 and 9 according to my SQL query (check below), but of course and retrieving nothing since I'm checking if cp.property_id = 9102
and later and checking if cp.property_id = 8801
which at the same time is impossible.
ID;type_id;name;desc;property_id,value
--------------------------------------
8;3832;"amplifier1";"";8801;"3"
8;3832;"amplifier1";"";9102;"4015"
9;3832;"amplifier2";"";8801;"3"
9;3832;"amplifier2";"";9102;"4016"
This is the query I have at this moment which retrieves nothing.
SELECT c.id, c.type_id, cp.property_id, cp.value
FROM components_component AS c
INNER JOIN components_componentproperty AS cp
ON c.id = cp.component_id
WHERE
(cp.property_id = 9102 AND cp.value IN ('4015', '4016'))
OR
(cp.property_id = 8801 AND cp.value = '3')
AND c.type_id = 3832
component ===> component_property <=== property
component
id serial NOT NULL,
type_id integer NOT NULL,
name character varying(50) NOT NULL,
description character varying(255),
component_property
id serial NOT NULL,
component_id integer NOT NULL,
property_id integer NOT NULL,
value character varying(255),
property
id serial NOT NULL,
code character varying(10),
preferred_name character varying(50),
My expected result would be:
id;name
-------
8;amplifier1
9;amplifier2