htyagi1
htyagi1

Reputation: 31

Find Exact Match Record and String Contains column 1 row word

I have 2 columns abc and bcd i want to compare abc data with bcd column exact match and sentence contain abc.

I have 2 columns abc and bcd i want to compare abc data with bcd column exact match and sentence contain word

Expected Result

enter image description here

Upvotes: 0

Views: 227

Answers (2)

Thorsten Kettner
Thorsten Kettner

Reputation: 95101

Are you trying to select all rows where there exists a row the abc of which matches the rows' bcd? Then use EXISTS.

select *
from mytable
where exists
(
  select null
  from mytable other
  where mytable.bcd like concat('%', other.abc, '%')
)
order by abc, bcd;

Upvotes: 1

Ben
Ben

Reputation: 2253

You can achieve it like this:

SELECT * FROM table_name WHERE table_name.abc like  CONCAT('%', table_name.bcd, '%');

This will return all records where string from abc column is contained in a string from bcd column.

Of course, replace table_name with your table name.

Upvotes: 0

Related Questions