简体   繁体   English

在表中搜索整个单词,如果找到则排除结果中的整个单词

[英]Search Table For Whole Word In Another Table, If Found Exclude From Result

Using MS Access, how would I create a query using SQL to search a table containing search terms (1 to 10 word phrases) for keywords or keyword phrases in another table, then exclude any matches to produce a list of search terms that did not match? 使用MS Access,我将如何使用SQL创建查询来搜索包含搜索词(1到10个单词短语)的表中的另一个表中的关键字或关键词短语,然后排除任何匹配项以生成不匹配的搜索词列表?

Search Terms Table Sample Data 搜索词表样本数据

  • tree house design 树屋设计
  • nelson tree house master 纳尔逊树屋大师
  • attachment point 附着点
  • attach blinder 附加盲目者
  • stainless steel nails 不锈钢钉

Negative Keywords & Keyword Phrases Sample Data 否定关键字和关键字短语示例数据

  • sign 标志
  • attach 连接
  • use 采用
  • steel

Desired Query Output 所需查询输出

  • tree house design 树屋设计
  • nelson tree house master 纳尔逊树屋大师
  • attachment point 附着点

NOTE: The Negative keywords include 'sign' and 'attach' but this should not prevent 'tree house design' and 'attachment point' from showing up in the result set. 注意:否定关键字包括'sign'和'attach',但这不应阻止'tree house design'和'attachment point'在结果集中显示。 I am using Access 2007. 我正在使用Access 2007。

here's the query 这是查询

SELECT SearchTerms.Phrase
FROM SearchTerms, Negatives
GROUP BY SearchTerms.Phrase
HAVING (((Max(InStr(" " & [phrase] & " "," " & [exclude] & " ")))=0));

Where SearchTerms is a table of the search terms and Phrase is the search term field, Negatives is the table with negative terms to exclude and Exclude is the field name in that table. 其中SearchTerms是搜索词的表,而Phrase是搜索词的字段,Negatives是要排除的负词的表,Exclude是该表中的字段名。

The trick is that I added spaces before & after the phrase, then looked for matches with the words to exclude and leading/trailing blanks. 诀窍是,我在词组的前后添加空格,然后寻找与要排除的词和前导/尾随空格的匹配项。 This way I can identify only the phrases that match whole words and not parts of words. 这样,我只能识别与整个单词匹配的短语,而不能识别单词的一部分。

Worked fine when I set up the tables & tested it. 当我设置表格并对其进行测试时,工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在该表的整个列中搜索关键字 - Search a key word in the whole column of that table 从另一个表中排除一个表中的字符串 - Exclude strings that are in one table from another table 最有效的方法,使用来自同一表的结果搜索SQL表,直到找到最终值 - most effecient way to search SQL table using result from same table until final value is found 如何遍历记录然后搜索到另一个表,如果没有找到,然后在从 oracle 中的另一个表中获取记录后插入它? - How to loop over records and then search into another table and if not found then insert it after fetching records from another table in oracle? 搜索表 - 如果找到结果,请不要搜索下一个表 - Searching a Table - If a result is found, don't search the next table 如果在另一个表中找到记录,请从表中选择 - Select from table if record found in another table 根据来自另一个表的信息搜索表 - Search table based on infromation from another table MySQL - 如果在另一个表上匹配,则从一个表中排除所有行 - MySQL - Exclude all rows from one table if match on another table 从一个表中选择值,其中排除另一个表中的值 - select values from a table where exclude values in another table 如果在另一个表上匹配,则从一个表中排除行 - MySql - Exclude rows from one table if match on another table - MySql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM