Search code examples
sqljoinfuzzy

Fuzzy (Like) Join not working


I have the below code to match on similar characters where possible and it only brings through results from subquery A. Please can someone assist? Thanks

    select 
        * 
    from 
        (
            Select 'Test' T
        )a
        left join
        (
            Select 'Test1' T
        )b
    on
        '%' + a.t + '%' 
    like 
        '%' + b.t  + '%'

Solution

  • The like pattern only goes on the right side of the operator. I think you intend:

    on (a.t like '%' + b.t + '%') or
       (b.t like '%' + a.t + '%')