WHERE 语句中的 MySQL CONCAT(多表)
我的问题很简单——至少我希望如此。我尝试连接 MySQL 中的两个表,并对连接字段执行 WHERE 语句以生成结果。以下是示例查询:
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
该查询似乎仍在从名称列中提取,并且不会返回任何结果。我已经尝试过这样做:
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
但它仍然没有产生任何结果。数据绝对在表中。约翰所在的公司是 IBM Computer Systems。 whole_name
字段将返回 'IBM Computer Systems John Smith'
,但对 '%IBM John%'
的查询不会返回任何内容。
有什么帮助吗?
谢谢, 格雷格
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. The whole_name
field would return 'IBM Computer Systems John Smith'
but a query on '%IBM John%'
return nothing.
Any help?
Thanks,
Greg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 IBM 和 John 之间需要一个 %...它正在文本中的某处查找“IBM John”...而不是 IBM,然后是 John 更远的地方..
Need a % between IBM and John... it's looking for "IBM John" somewhere in the text... not IBM then John somewhere further along..