Q:

Need help building SQL query for single table

I have a table with the following fields:
ID 
brandID
productID

I want to know how many distinct brandIDs have at least one record in this table with both productID 1 and productID 2.  For example:
ID|brandID|productID
1 | 1     | 1
2 | 1     | 2
3 | 1     | 2
4 | 2     | 2
5 | 3     | 1
6 | 3     | 1

In the above sample table, only brandID 1 has a row with productID 1 and productID 2.  brandIDs 2 and 3 only have one product or the other.
How do I build a query to get this count of distinct brandIDs that contain both productID 1 and 2?

A:

select COUNT(*)
from (
    select brandID
    from MyTable
    where productID in (1, 2)
    group by brandID
    having count(distinct productID) = 2
) a

