My problem is pretty simple - at least I hope it is. I am try to join two tables in MySQL and the perform a WHERE statement on a concatenated field to produce a result. Here is the sample query:
SELECT a.name, b.company, concat_ws(' ', a.company, b.name) as whole_name
FROM users as a
INNER JOIN company as b on a.company_id = b.company_id
HAVING whole_name LIKE '%IBM John%'
LIMIT 25
This query seems to still be pulling from the name column and will return no results. I've tried this by doing:
SELECT a.name, b.company, concat_ws(' ', a.company, b.name) as whole_name
FROM users as a
INNER JOIN company as b on a.company_id = b.company_id
WHERE concat_ws(' ', a.company, b.name) LIKE '%IBM John%'
LIMIT 25
And it still doesn't yield any results. The data is absolutely in the table. The company for John is IBM Computer Systems.开发者_如何学JAVA The whole_name
field would return 'IBM Computer Systems John Smith'
but a query on '%IBM John%'
return nothing.
Any help?
Thanks, Greg
Need a % between IBM and John... it's looking for "IBM John" somewhere in the text... not IBM then John somewhere further along..
精彩评论