开发者

TSQL - like question

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜