开发者

TSQL - like question

开发者 https://www.devze.com 2023-02-17 18:39 出处:网络
What is a better way to write the following transact SQL? select * from table1 whe开发者_如何学JAVAre columnA like \'%ABC%\' and columnB = 1

What is a better way to write the following transact SQL?

select * from table1 whe开发者_如何学JAVAre columnA like '%ABC%' and columnB = 1

select * from table1 where columnA like '%DEF%' and columnB = 1

select * from table1 where columnA like '%GHI%' and columnB = 1

is it possible to consolidate the above 3 sql statements into a single select statement


select * from table1 
where (columnA like '%ABC%' 
       or columnA like '%DEF%'
       or columnA like '%GHI%')
    and columnB = 1


select *

from table1

where columnB = 1 and 
         (columnA like '%ABC%' or 
          columnA like '%DEF%' or 
          columnA like '%GHI%')


You can try this

select * from table1
where (columnA like '%ABC%'
   or columnA like '%DEF%'
   or columnA like '%GHI%')
 and columnB = 1
0

精彩评论

暂无评论...
验证码 换一张
取 消