Query using ILIKE with IN
Asked Answered
T

2

8

Is it possible to run a query using ILIKE with the IN function? For example:

SELECT store_names
FROM stores
WHERE states ILIKE IN (SELECT location
                       FROM   locations
                       WHERE  stateID = 1)

I want to run the results returned from the nested query through the ILIKE function. Is there a way to do this?

Ten answered 10/10, 2012 at 23:13 Comment(0)
T
6

Can be simpler:

SELECT s.store_names, l.location
FROM   stores s
JOIN   locations l ON s.states ILIKE l.location
WHERE  l.stateid = 1

You can check the resulting query plan with EXPLAIN ANALYZE.

You may need to add leading and trailing % to get partial matches:

... ON s.states ILIKE ('%' || l.location || '%')
Troglodyte answered 10/10, 2012 at 23:24 Comment(0)
L
1

SELECT store_names FROM stores WHERE states ILIKE any (SELECT location FROM locations WHERE stateID = 1)

Larcenous answered 29/11, 2023 at 6:46 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rubicund

© 2022 - 2025 — McMap. All rights reserved.