netraider
netraider

Reputation: 257

SQL LIKE wildcard assistance

I need your help with a simple query that I have but not sure how change the LIKE wildcard accordingly. This to query an Oracle database.

Could you please assist with the below,

select * from table_name
where field1 like '1%'
    or field2 like '2%'
    or field3 like '3%'
    or field4 start with 4 but not 4123

Upvotes: 1

Views: 111

Answers (2)

Hambone
Hambone

Reputation: 16407

Here is an alternate approach:

select *
from table_name
where
  substr (field1, 1, 1) in ('1', '2', '3', '4') and
  field1 not like '4123%'

Upvotes: 0

Michael
Michael

Reputation: 184

select * 
from table_name 
where field1 like '1%' 
or field2 like '2%' 
or field3 like '3%' 
or (field4 like '4%' and field4 not like '4123%')

Upvotes: 4

Related Questions