0

I want to search question no. which can be 1, 1a, 1b, 2, 2c, 11. How can I to search 1 getting 1, 1a, 1b but not 11. And if I search 1b, only 1b comes out. Is there any function helps?

using mysql

DATA:
id    |question   |q_no.
1     |XX         |1
2     |ABC        |1a
3     |ED         |1c
1     |CD         |11

Desired sets:
when searching "1":
1     |XX         |1
2     |ABC        |1a
3     |ED         |1c

when searching "1a":
2     |ABC        |1a

sorry for being late

3
  • 4
    What RDBMS are you using? Commented Aug 29, 2015 at 14:56
  • 2
    Your question is too vague to be answered. Try: (1) including sample data; (2) desired results; (3) code that you have written; (4) tag the question with the database you are using. Also, a SQL Fiddle can help. Commented Aug 29, 2015 at 14:56
  • Make a function do_sql which takes the first argument for a LIKE where clause in the sql command the function will create. Than call the function with the desired parameters: `do_sql "1b"``. Or explain what you really want and what you have tried. Commented Aug 29, 2015 at 14:58

2 Answers 2

1

May be this can help. It run in mysql.

SELECT---
FROM---
WHERE question_no REGEXP '1[^1]'

It will show question_no start with character '1' and followed by except character '1'

Sign up to request clarification or add additional context in comments.

Comments

1

I think regexp is your best approach:

where question_no regexp concat('^', $SearchQ, '[^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.