Search code examples
sqlsql-serversql-like

SQL, Using LIKE operator to select from two tables


I need to select from table1.cloumn when its value contain a value from table2.column

I was trying this:

select * from Products1 where sku like '%' + (select sku from Products2) + '%' 

Solution

  • You can try to use exists with a subquery.

    select * 
    from Products1 t1
    where exists(
        select 1
        from Products2 t2
        WHERE t1.sku like '%' + t2.sku+ '%' 
    )
    

    sqlfiddle