LIKE function and concatination

Last post 01-19-2012 5:27 PM by Boudewijn Beks. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 01-19-2012 5:27 PM

    LIKE function and concatination

    hello all, I have two tables for input: 1) keywords SELECT 'myshop' AS keyword union SELECT 'myshop bike' AS keyword union SELECT 'table' AS keyword 2) brandname SELECT 'myshop' AS brandname, 1 AS metric in a third table I want to retrieve all records from 'keywords' in which the keyword matches brandname in 'brandname'. In order to do so I wrote the following query: SELECT kw.keyword AS brand FROM keywords AS kw left JOIN brandname AS bn ON kw.keyword = bn.brandname WHERE kw.keyword LIKE '%'+bn.brandname+'%' I would expect that my result set would look the same as in: SELECT kw.keyword AS brand FROM keywords AS kw left JOIN brandname AS bn ON kw.keyword = bn.brandname WHERE kw.keyword LIKE '%'+'myshop'+'%' however, the first query results in: myshop, the second query results in 'myshop', 'myshop bike'. What is the reason why my query is not working? Or is there another way to match columns from one table to parts of columns from another table (with the LIKE function) ? Thank you for your help, Boudewijn
Page 1 of 1 (1 items)