How to use LIKE with IN in DB2?

流过昼夜 提交于 2019-12-19 05:58:09

问题


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:

SELECT * FROM abc WHERE column1 LIKE IN (a%,b%,c%)

回答1:


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:


You can't. Write it as:

column1 LIKE 'a%' OR column1 LIKE 'b%' OR column1 LIKE 'c%'



回答3:


As the other folks say you can use a list of OR conditions to specify the conditions.

You can also use a temporary table or subquery in the from clause. Here is an example of the subquery in the from clause:

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;


来源:https://stackoverflow.com/questions/11838919/how-to-use-like-with-in-in-db2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!