本文介绍了SQL选择行,其中字段包含另一个表的字段中的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MySQL,我有一个带有名称字段的表.我想对照一组关键字"来检查该名称字段,这些关键字表明该名称不是一个人,而是一个企业.

Using MySQL, I have a table with a name field. I want to check that name field against a set of "keywords" that indicate that the name is not a person, but a business.

换句话说:如果名称包含任何关键字,则获取整行.

In words: Get the entire row if the name contains any of the keywords.

我的尝试:SELECT * FROM leads WHERE CONTAINS(leads.name, (SELECT word FROM keywords));(返回子查询返回多于1行")

My attempt:SELECT * FROM leads WHERE CONTAINS(leads.name, (SELECT word FROM keywords));(Returns "Subquery returns more than 1 row")

推荐答案

它不能那样工作.您可以改用联接

It does not work like that. You can use a join instead

SELECT l.*
FROM leads l
JOIN keywords k on instr(leads.name, word) > 0

这篇关于SQL选择行,其中字段包含另一个表的字段中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:34