I am going to use a for/each loop, to search different names (table1
) among textual information of records in another table (table2
) using regular expressions.
SELECT id FROM "table1"
where tags ~* 'south\s?\*?africa'
or description ~* 'south\s?\*?south'
order by id asc;
but I do not know how to put it in a for each loop!
table1
:
t1ID | NAME
1 | Shiraz
2 | south africa
3 | Limmatplatz
table2
:
t2ID |TAGS | DESCRIPTIONS
101 |shiraz;Zurich;river | It is too hot in Shiraz and Limmatplatz
201 |southafrica;limmatplatz| we went for swimming
I have a list of names in table1
. Another table has some text information that might contain those names.
I would like to get back the id of table2
that contains items in table1
with the id of the items.
For example:
t2id | t1id
101 |1
101 |3
201 |2
201 |3
My tables have 60,000 and 550.000 rows. I need to use a way that time wise be efficient!