How to use LIKE with IN in DB2?

后端 未结 4 1424
名媛妹妹
名媛妹妹 2021-01-11 12:14
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 que

相关标签:
4条回答
  • 2021-01-11 12:19

    If you really want to look for strings starting with a, b or c, you may opt for :

    SELECT * 
    FROM abc
    WHERE LEFT(column1, 1) IN ('a', 'b', 'c')
    

    I assume your case is actually more complex, but maybe you can adapt this snippet to your needs...

    0 讨论(0)
  • 2021-01-11 12:34

    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;
    
    0 讨论(0)
  • 2021-01-11 12:36

    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%'
    
    0 讨论(0)
  • 2021-01-11 12:45

    You can't. Write it as:

    column1 LIKE 'a%' OR column1 LIKE 'b%' OR column1 LIKE 'c%'
    
    0 讨论(0)
提交回复
热议问题