0

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
0

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 + '%'
2
  • PostgreSQL doesn't accept +as a string concatenate operator. It also doesn't accept # as a table name character (see here). – Vérace Dec 11 '20 at 10:48
  • thanks, pix1958, I used " || " instead of " + " – Vishal Dec 16 '20 at 21:18
0

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, privacy policy and cookie policy

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