我想检索使用相同ID的多个行。 因此,具有这种表“component_property”,我想有作为结果2条记录,ID的:8和9,根据我的SQL查询(请查看下面),但当然和检索什么的,因为我正在检查是否cp.property_id = 9102
后来和检查是否cp.property_id = 8801
,其在同一时间是不可能的。
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"
这是查询我在这一刻它检索什么。
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_property <===属性
零件
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),
属性
id serial NOT NULL,
code character varying(10),
preferred_name character varying(50),
我预期的结果将是:
id;name
-------
8;amplifier1
9;amplifier2