filter table rows within range of related column
Fiddle
with user_defined_params as (
  select 2 as target_group_id,
  8 as first_id,
  11 as second_id
),
target_value_bounds AS (
  select min(value) as minval, max(value) as maxval
  from data where group_id=(select target_group_id from user_defined_params)
  AND ((id=(select first_id from user_defined_params))
       OR (id=(select second_id from user_defined_params)))
)
select * from data
where group_id=(select target_group_id from user_defined_params)
           AND value &gt;= (select minval from target_value_bounds)
           AND value &lt;= (select maxval from target_value_bounds);

If you're using this from a programming language, you'll definitely want to do away with the user_defined_params CTE and just use named query parameters.