Question: I have two tables: t1 and t2. There are three steps: in t1 select a Set\_of\_strings with id = 1 ("1a" and"3c"). From t1 select strings that correspond to OPTIONID ='A' and that contain sub string from the Set\_of\_strings.

t1 

```
ID  NAME   
1   "1a"   
2   "2b"   
1   "3c"   

```

t2 

```
OPTIONID    TXT   
  A     "7h 9t"   
  B     "1a 8n"   
  A     "2b 4r"    
  A     "3c 6u" 

```

---

```
SELECT 
    NAME 
FROM t1 
WHERE ID = 1; -- 1a, 3c

SELECT
    TXT 
FROM t2 
WHERE OPTIONID = 'A' AND (TXT LIKE '%1a%' OR TXT LIKE '%3c%') --"3c 6u"

```

How to automate `TXT LIKE '%1a%' OR TXT LIKE '%3c%'` part?

---

`LIKE'%1a%'` is safe because of all entries have the same format, e.i. there is no `1a2` in `TXT` column.

Answer: 
See if this works:

```
SELECT DISTINCT
    t2.TXT 
FROM 
    t2
    INNER JOIN t1 ON
        t1.ID=1 AND
        t2.TXT LIKE '%'+t1.NAME+'%'
WHERE 
    t2.OPTIONID = 'A';

```
I think you just want a join

```
SELECT TXT 
FROM t2
JOIN t1 on t2.TXT = t1.NAME and t1.ID = 1
WHERE OPTIONID = 'A'

```