Pinch Pinch - 1 year ago 71
SQL Question

SQL Joining column is a subset of another

Assuming the following tables:

Table A
Some Apples are Green
Many Bananas are Yellow
Carrots are Orange

Table B

I would like to
inner join
these tables where
is a subset of

Results would be

[Description] [Fruits]
Some Apples are Green Green
Many Bananas are Yellow Yellow
Carrots are Orange Orange

Answer Source

Demo Here

select dataa,b.colorname from #temp t
cross apply
(select  replace(t.dataa,colorname,'') as rplc,colorname
from #colors)b
where dataa<>rplc
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download