Prashant Tendulkar
Prashant Tendulkar

Reputation: 7

simple sql query. how to solve it..?

ID  MOBILE
1   9869600733
2   9869600793
3   9869600799

all id whose mobile number containing 9 three times... ?

Upvotes: 0

Views: 34

Answers (2)

Billy Ferguson
Billy Ferguson

Reputation: 1439

Your RDBMS is needed to know the EXACT solution, but this works for most. I used MOBILE_ID_TABLE because you didn't provide table name. Depending on your RDBMS LIKE will want % or *.

SELECT ID FROM MOBILE_ID_TABLE WHERE MOBILE LIKE '%9%9%9%';
SELECT ID FROM MOBILE_ID_TABLE WHERE MOBILE LIKE '*9*9*9*';

Upvotes: 1

Esteban P.
Esteban P.

Reputation: 2809

my solution would be:

the statement will return all records, where the MOBILE column includes three times the number 9.

SELECT *
  FROM youtable
 WHERE (LEN(MOBILE) - LEN(REPLACE(MOBILE,'9',''))) = 3

Upvotes: 0

Related Questions