SELECT * FROM abc WHERE column1 IN (a1,b1,c1)
I want to use LIKE with this select query; how can I write LIKE statement with IN, similar to the query below:
我想在这个选择查询中使用LIKE;如何用IN编写LIKE语句,类似于下面的查询:
SELECT * FROM abc WHERE column1 LIKE IN (a%,b%,c%)
3 个解决方案
#1
8
You can't combine like
with in
. Write it as separate comparisons:
你不能把它组合起来。把它写成单独的比较:
select column1
from abc
where column1 like 'a%' or column1 like 'b%' or column1 like 'c%'
#2
6
You can't. Write it as:
你不能。把它写成:
column1 LIKE 'a%' OR column1 LIKE 'b%' OR column1 LIKE 'c%'
#3
2
As the other folks say you can use a list of OR conditions to specify the conditions.
正如其他人所说,您可以使用OR条件列表来指定条件。
You can also use a temporary table or subquery in the from clause. Here is an example of the subquery in the from clause:
您还可以在from子句中使用临时表或子查询。以下是from子句中子查询的示例:
select column1
from abc
, table(
(select 'a%' as term from SYSIBM.SYSDUMMY1)
union all
(select 'b%' from SYSIBM.SYSDUMMY1)
union all
(select 'c%' from SYSIBM.SYSDUMMY1)
) search_list
where abc.column1 like search_list.term;
#1
8
You can't combine like
with in
. Write it as separate comparisons:
你不能把它组合起来。把它写成单独的比较:
select column1
from abc
where column1 like 'a%' or column1 like 'b%' or column1 like 'c%'
#2
6
You can't. Write it as:
你不能。把它写成:
column1 LIKE 'a%' OR column1 LIKE 'b%' OR column1 LIKE 'c%'
#3
2
As the other folks say you can use a list of OR conditions to specify the conditions.
正如其他人所说,您可以使用OR条件列表来指定条件。
You can also use a temporary table or subquery in the from clause. Here is an example of the subquery in the from clause:
您还可以在from子句中使用临时表或子查询。以下是from子句中子查询的示例:
select column1
from abc
, table(
(select 'a%' as term from SYSIBM.SYSDUMMY1)
union all
(select 'b%' from SYSIBM.SYSDUMMY1)
union all
(select 'c%' from SYSIBM.SYSDUMMY1)
) search_list
where abc.column1 like search_list.term;