Test Aliases

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

with Person as
(
select 1 as id, 'joe' as name
),
Obstacle AS
(
select 1 as id, 'river' as obstacle
),
Person_overcomes_obstacle AS
(
select 1 as obstacle_id, 1 as person_id
)

SELECT p.id, p.name /*Or use COUNT(*) or wrap in Exists 
                     if you don't care about ids and names*/
FROM Person p
WHERE NOT EXISTS
   (SELECT * FROM Obstacle o
    WHERE NOT EXISTS 
    (
       SELECT * FROM Person_overcomes_obstacle poo
       WHERE poo.person_id = p.id and o.id = poo.obstacle_id
    )
)

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results