Oracle SQL,在一列中搜索包含另一列字符串的字符串

Oracle SQL,在一列中搜索包含另一列字符串的字符串,sql,database,oracle,subquery,Sql,Database,Oracle,Subquery,目前有这个表,需要能够找到包含人名的句子 ID FIRSTNAME LASTNAME EMAIL PHRASE -------- --------------- ------------ --------------------------- --------------------------------------------------------------- 1

目前有这个表,需要能够找到包含人名的句子

ID         FIRSTNAME       LASTNAME        EMAIL                         PHRASE
--------  --------------- ------------     ---------------------------   ---------------------------------------------------------------          
1          John            Smith           jsmith@faker.com              I'm the same as other people.
2          Sarah           Lane            saralane23@faker.com          I'm different from other people
3          Allen           Borazt          allenB@faker.com              I guess I need another job.
4          Mike            Himmy           mh@faker.com                  We have a great time. John Smith really enjoys his time out.
5          Jillian         Carters         jcartrs@faker.com             What happened to the car? 
6          Steven          Oarts           SteveO2@faker.com             Just chillin' over in the pool
7          Ronald          Donalds         don@faker.com                 Just in case you were wondering
8          Nancy           Arist           nArist@faker.com              What I really want is Paul Blarts movie.
9          Paul            Blart           paulb@faker.com               I think Nancy Arist hair color is cool.
现在我的查询看起来像这样,但它返回“未选择行”

我想要的结果是这样的

ID         FIRSTNAME       LASTNAME        EMAIL                         PHRASE
--------  --------------- ------------     ---------------------------   ------------------------------------------------------------------------------------------------------------------------               
4          Mike            Himmy           mh@faker.com                  We have a great time. John Smith really enjoys his time out.
8          Nancy           Arist           nArist@faker.com              What I really want is Paul Blarts movie.
9          Paul            Blart           paulb@faker.com               I think Nancy Arist hair color is cool.

执行子查询并使用exists检查在短语列中是否找到fname或lname

SELECT A.*
FROM Table1 A
WHERE EXISTS (
          SELECT * 
           FROM Table1 B
           WHERE B.Phrase Like '%' || A.FirstName || '%'
           OR  B.Phrase Like '%' || A.LastName  || '%')
添加查询以忽略区分大小写


嗯。问题是您只查看一行中的值。我想你想要:

select t.*
from table t
where exists (select 1
              from table t2
              where t.Phrase Like '%' || t2.FirstName || '%'
             );

我不明白你的预期产出。你可以考虑使用全文搜索。因此,基本上,如果要查找任何包含某人名字或姓氏的短语,我都找不到colimn1的表和样本数据。我本来打算用随机表名发布这篇文章,但我认为如果我输入数据,可能更容易阅读,只是编辑了它。短语定义在同一个表中,它集所有功能于一身。在线查看时,它说我可能需要使用子查询,但执行您的解决方案仍然会导致“未选择行”。我没有向右滚动,因此看不到列短语。我更新了我的答案很好!,感谢这么多的工作,只是添加了一个修剪的名称部分,并得到了我的查询
SELECT T1.*
FROM Table T1, Table T2
WHERE upper(T1.Phrase) Like '%' || upper(T2.FirstName) || '%'
OR upper(T1.Phrase) Like '%' || upper(T2.LastName) || '%';
select t.*
from table t
where exists (select 1
              from table t2
              where t.Phrase Like '%' || t2.FirstName || '%'
             );