2

I have table 'A' with column 'col' with values:

a.b.1.c

a.b.2.c

a.b.26.d

If I execute this Select it works:

SELECT
*
FROM
A
WHERE col LIKE 'a.b.[2-9]%';

If I execute this one, it does'nt:

SELECT
*
FROM
A
WHERE col LIKE 'a.b.[2-9][0-9]*%';

The expected result of the query should be:

a.b.2.c

a.b.26.d

So, I need the "*" to be optional the second number

Why is this happening? How could I make it work to allow numbers greater than 9?

Here are both fiddle1 fiddle2:

3
  • 1
    * is the culprit in the second one. Commented Jul 12, 2017 at 13:36
  • the * in your second query is the problem. Why is it there Commented Jul 12, 2017 at 13:41
  • if the [0-9] is optional and you require the results to include a.b.2.c, then what's wrong with your first statement ? Just curious to know :) Commented Jul 12, 2017 at 13:50

4 Answers 4

3
  • not needed. Try this;

    select * from a
    WHERE col LIKE 'a.b.[2-9][0-9]%' or col like 'a.b.[2-9]%'
    
Sign up to request clarification or add additional context in comments.

1 Comment

But I need it to be optional, it should also return me the a.b.2.c
2

Try without * and use or operator

SELECT
*
FROM
A
WHERE col LIKE 'a.b.[2-9]%' or col LIKE 'a.b.[2-9][0-9]%';

Comments

1

Try this (without *):

SELECT
*
FROM
A
WHERE col LIKE 'a.b.[2-9][0-9]%';

1 Comment

But I need it to be optional, it should also return me the a.b.2.c
0
SELECT * FROM A WHERE col LIKE 'a.b.[2-9][0*-9]%';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.