You can do this with a nested select
and a case
statement. The nested select uses like
to see if there are any rows that meet the similarity condition. Note that the like
will find a match if the values are identical as well as when the B
column starts with the A
column:
select t.*,
(case when exists (select 1 from table t2 where t1.B like concat(t2.A, '%'))
then 'Yes'
else 'No'
end) as C
from table t;
EDIT:
If by contain, you want '1401'
to also match '40'
, then the pattern for the like
should be: concat('%', t2.A, '%')
.