Michael Pell Michael Pell - 3 months ago 12
SQL Question

PostgreSQL wildcard LIKE for any of a list of words returned by Subquery

This is very much like PostgreSQL wildcard LIKE for any of a list of words, except instead of wanting to match on a static list of words, I want to match on a list of words returned by a subquery.

Something like this:

SELECT *
FROM people
WHERE name ~* (SELECT concat(last_name, ', ', first_name)
FROM other_people) + wildcard in this direction

Answer
select *
from people
where name like any (
    select concat(last_name, ', ', first_name, '%')
    from other_people
)