过滤 table where 字段喜欢子查询的结果
Filtering table where field like the result of a subquery
我正在尝试创建一个查询来查找包含子查询结果的所有用户名。我在下面写了一些伪代码:
select <field1>
from <table1>
where <field> like
( select <field2> from <table2> )
我基本上想结束我的查询比较:
table1.field1 like '%' || table2.field2 || '%'
这可能吗?
使用exists
:
select <field1>
from <table1> t1
where exists (select <field2>
from <table2> t2
where t1.field1 like '%' || t2.field2 || '%'
);
您也可以使用 join
执行此操作,但之后您可能必须删除重复项。
我正在尝试创建一个查询来查找包含子查询结果的所有用户名。我在下面写了一些伪代码:
select <field1>
from <table1>
where <field> like
( select <field2> from <table2> )
我基本上想结束我的查询比较:
table1.field1 like '%' || table2.field2 || '%'
这可能吗?
使用exists
:
select <field1>
from <table1> t1
where exists (select <field2>
from <table2> t2
where t1.field1 like '%' || t2.field2 || '%'
);
您也可以使用 join
执行此操作,但之后您可能必须删除重复项。