Mohsin Shaikh
Mohsin Shaikh

Reputation: 33

SQL- Subquery returns more than 1 row

This is a part of a complex sub query, I am getting the above error on this query:

select
  product_id
from
  oc_product_filter
where
  product_id IN (
                  (select
                     a.product_id
                   from
                     oc_product_filter a
                   where
                     a.filter_id in (8)
                  ),
                  (select
                     b.product_id
                   from
                     oc_product_filter b
                   where
                     b.filter_id in (25)
                  )
                );

Upvotes: 0

Views: 466

Answers (1)

Guillaume Thomas
Guillaume Thomas

Reputation: 2310

What comes after the IN is supposed to be a tuple of elements. You have a tuple of two elements where each element is the result of a subquery. You're allowed to do so only if the subquery returns 1 row and 1 column. It looks it's not the case here.

Your query seems too complex for what it's supposed to do.

Why not:

SELECT product_id
FROM oc_product_filter
WHERE filter_id IN (8, 25);

Upvotes: 1

Related Questions