首页 > 解决方案 > 从列表中选择标题包含任何术语的行

问题描述

我有一个包含 product_id、product_url、email、product_title 等的数据集。

我想从 400 多个单词的列表中提取 product_title 包含某些形容词(Fabulous、Stunning、Rare、Amazing、Unique 等)的行。

如果不对每个单词执行单独的选择功能,我该如何做到这一点?我正在使用 SQLite

标签: sqlsqlite

解决方案


您可以使用以下命令构造单个查询or

select t.*
from t
where t.title like '%Fabulous%' or
      t.title like '%Stunning%' or
      . . .  ;

如果单词存储在单独的表中,您可以使用exists

select t.*
from t
where exists (select 1
              from interesting_words iw
              where t.title like '%' || iw.word || '%'
             );

推荐阅读