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


i want it to return


2 Answers 2


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')

Select      *
From        #Test 
Where       ColB Like '%' + ColA + '%'
  • PostgreSQL doesn't accept +as a string concatenate operator. It also doesn't accept # as a table name character (see here).
    – Vérace
    Commented Dec 11, 2020 at 10:48
  • thanks, pix1958, I used " || " instead of " + "
    – Vishal
    Commented Dec 16, 2020 at 21:18

select * from table_name where "column1" ILIKE '%'||"column2"||'%';

pix1985 got close. Replace + with two pipes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.