You can use intersect
, but this is on the artwork
table. So the following returns the artists who have both drawings and paintings:
select aw.artist_id
from artwork aw
where aw.technique = 'drawing'
intersect
select aw.artist_id
from artwork aw
where aw.technique = 'painting' ;
To get the artist information you would use join
, exists
, or in
:
select a.*
from artist a
where a.artist_id in (select aw.artist_id
from artwork aw
where aw.technique = 'drawing'
intersect
select aw.artist_id
from artwork aw
where aw.technique = 'painting'
);
There are other methods, such as conditional aggregation. I would be inclined to use:
select a.*
from artist a join
artwork aw
using (artist_id)
where aw.technique in ('drawing', 'painting')
group by a.artist_id -- presumably this is a primary key
having count(distinct aw.technique) = 2;
Or the exists
method that GMB suggests.