I have two queries in which I need only the number of shared records, but the only difference in the queries is a single field value.
Example
SELECT COUNT(*) AS group_a
FROM tbl
WHERE category = 'value_a'
SELECT COUNT(*) AS group_b
FROM tbl
WHERE category = 'value_b'
How can I get something like this: (pseudo)
SELECT COUNT(*) AS group_a, COUNT(*) AS group_b
FROM tbl
WHERE category IN ('value_a', 'value_b')
But the results are like this.
group_a , group_b
56, 101
I thought the CASE statement in the query would filter two, but how to implement it? or is there a better way?
I am doing UNION right now, but would like to know if I can return one record with two results
source
share