0

I have the query as:

SELECT i.id AS id
    FROM table_a i
    WHERE (i.cat_id IN (92, 224))
    GROUP BY id
    HAVING (COUNT(i.cat_id) = 2 AND SUM(i.cat_id) = 316)

    UNION
    (
        SELECT i.id AS id
        FROM table_a i
        WHERE (i.cat_id IN (92, 227))
        GROUP BY id
        HAVING (COUNT(i.cat_id) = 2 AND SUM(i.cat_id) = 319)
    )

How to optimize this query?

1 Answer 1

1
SELECT i.id AS id
    FROM table_a i
    WHERE (i.cat_id IN (92, 224) OR i.cat_id IN (92, 227))
    GROUP BY id
    HAVING (COUNT(i.cat_id) = 2 
       AND (SUM(i.cat_id) = 316 OR SUM(i.cat_id) = 319 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.