'want to get country area code from phone number present in mysql db
I'm having phone number 1212010089
and want to know from which country I'm getting this number.I do have a table_1
which is having column1 area_code
where lots of area codes are available and column2 location
which is having an equivalent location according to that area_code
the maximum length of area_code
is 7 in it so please suggest me an appropriate sql query by which I can find the location
from that number.
Thanks in advance.
Solution 1:[1]
Try something like:
SELECT location
FROM table_1
WHERE '237690000000' LIKE CONCAT(area_code,'%')
AND LENGTH(area_code)=
(SELECT MAX(LENGTH(area_code))
FROM table_1
WHERE '237690000000' LIKE CONCAT(area_code,'%'));
Solution 2:[2]
you can also try this:
SELECT location FROM table_1 WHERE '23769111111' LIKE CONCAT(area_code,'%') ORDER BY LENGTH area_code DESC LIMIT 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ihab hamad |