I have two tables. One has users IDs, the second user IDs and what they bough.
I trying to select users ID's (no dupes) that bough
select distinct usr_id
where productname = 'thing1'
and usr_id not in (select usr_id
where productname = 'thing2');
from accounts acc
inner join purchases_tbl ptbl
on acc.usr_id = ptbl.usr_id
and ptbl.productname = 'thing1'
where ptbl.productname != 'thing2'
You can group by the users and then take only those having at least one time bought 'thing1' and never 'thing2'
select usr_id from purchases_tbl group by usr_id having sum(case when productname = 'thing1' then 1 else 0 end) > 0 and sum(case when productname = 'thing2' then 1 else 0 end) = 0