I need a procedure for below dynamic query. In that procedure, f_id
and value
are input parameters. f_id
and value
are collections of values.
For example
f_id=1780
value=ABC
f_id=22483
value=`sasdfa`
f_id=3334
value=soap
So in the below query and exits part will be added dynamically depends on the count of f_id
and value
.
select distinct
v1.entity_id
from
values v1
inner join
listings l on v1.entity_id = l.entity_id
where
l.c_id = 83
and exists (select 1 from values v2
where v1.entity_id = v2.entity_id
and v2.f_id = 1780 and (value = ABC))
and exists (select 1 from values v3
where v1.entity_id = v3.entity_id
and v3.field_id = 22483 and (value = sasdfa))
and exists (select 1 from values v4
where v1.entity_id = v4.entity_id
and v4.field_id = 3334 and (value = soap))
and exists (select 1 from values v5
where v1.entity_id = v5.entity_id
and v5.field_id = 3433 and (value=paste))
order by
l.id desc