Reputation: 754
I have this query
Select Model_Number
From Guitar.Fenders
Where Model_number LIKE ('5%' OR '6%')
This doesn't work.
I only want the query to return model numbers that begin with 5 or 6.
Upvotes: 0
Views: 59
Reputation: 5135
There are a couple of ways you can do this, one by making use of LIKE
and the other by making use of IN
:
LIKE
Select Model_Number
From Guitar.Fenders
Where Model_number LIKE '5%' OR Model_Number LIKE '6%'
IN
Select Model_Number
From Guitar.Fenders
Where LEFT(Model_number, 1) IN ('5','6')
I'd prefer to use the IN
statement in case the 'conditions' are likely to increase.
If not, you could simplify this by making use of:
Select Model_Number
From Guitar.Fenders
WHERE Model_number >= '5' AND Model_number < '7'
You can choose any of these three which suits your needs.
Hope this helps!!!
Upvotes: 3
Reputation: 7693
You can define a Regular Expression for this case, something like:
^[56].*$
And then pass the regular expression using Xquery.
Upvotes: 0
Reputation: 3187
This is probably the easiest way.
Select Model_Number
From Guitar.Fenders
Where Model_number LIKE '5%' OR Model_number like '6%'
Hope this helps, MatthewJ
Upvotes: 0
Reputation: 12027
Select Model_Number From Guitar.Fenders Where (Model_number LIKE '5%' OR Model_number LIKE '6%')
Upvotes: 0