I think what I am after is fairly elementary, but I haven't been able to get the expected results through my experiments so far.
I am operating on one table, where the values from one known row determine which other rows from the same table are selected.
To illustrate what I want in two queries:
SELECT id, gender, sport, age
FROM
person
WHERE
id = '123';
-- using id, gender, sport and age as inputs into the next query
SELECT id, age, sport, gender
FROM
person
WHERE
id != $1 AND looking_for_gender = $2 AND looking_for_sport = $3 AND min_age <= $4;
I've been trying different varieties of joins and subqueries in the from clause but not being able to get a satisfactory result to get the same from a single query.
Thanks in advance for any direction.