Question: I'm using T-SQL

I have a table: user session with platform source.

I need to get users who used only "Android" and "Desktop". 

Data Example:

```
ID | Source  | DateTime
 1 | Android | 2016-06-01
 1 | Desktop | 2016-06-01
 2 | Android | 2016-06-02
 3 | iOS     | 2016-06-01
 3 | Desktop | 2016-06-02
 3 | Android | 2016-06-03 

```

Expected result:

```
ID = 1

```

* ID = 2 is wrong, because it has only "Android"
* ID = 3 is wrong, because it has "IOS"

Answer: 
I call this a set-within-sets query. I like to approach this using `group by` and `having`, because this is a very flexible method for expressing these conditions:

```
select id
from t
group by id
having sum(case when source = 'Android' then 1 else 0 end) > 0 and -- has Android
       sum(case when source = 'Desktop' then 1 else 0 end) > 0 and -- has Desktop
       sum(case when source not in ('Android', 'Desktop') then 1 else 0 end) = 0 -- has nothing else

```
Try this

```
select id from your_table
group by id
having 
max(case when source in ('Android') then 1 else 0 end))=1
and
max(case when source in ('Desktop') then 1 else 0 end))=1
and count(distinct source)=2

```