Postgresql – how to select records from two columns where one column consist word from second column

postgresqlquery

In postgres I want to select rows where column1 matches column2 for corresponding row and returns result having same values as well as records consisting word from column1.

select * from table_name where "column1" ILIKE "column2"; 

i am using above query but it returns exact matches, it should also return rows consisting words from column1 in column2.

column1 | column2
hello   | hello
please  | please guys
help    | help me
query   | website

my above query returns

column1
hello

i want it to return

column1
hello
please
help

Best Answer

Do you need it to be case sensitive? If not try using LIKE

Create Table #Test
(
ColA Varchar(100)
,ColB Varchar(100)
)

Insert Into #Test
Values ('TEST', 'THIS IS A TEST')
,('String', 'This Also has word string in it')
,('ABC','DEF')
,('123','456')


Select      *
From        #Test 
Where       ColB Like '%' + ColA + '%'