WHERE 语句中的 MySQL CONCAT(多表)

发布于 2024-10-05 14:07:59 字数 799 浏览 8 评论 0原文

我的问题很简单——至少我希望如此。我尝试连接 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故乡的云 2024-10-12 14:07:59

在 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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文