w3resource

MySQL String Exercises: Extract the last 4 character of phone numbers

MySQL String: Exercise-9 with Solution

Write a query to extract the last 4 character of phone numbers.

Sample table: employees


Code:

SELECT RIGHT(phone_number, 4) as 'Ph.No.' FROM employees;

Sample Output:

 Ph.No.
4567
4568
4569
4567
4568
4569
4560
5567
4569
4169
4269
4369
4469
4567
4561
4562
4563
4564
4565
4566
1234
2234
3234
4234
5234
1214
1224
1334
1434
5234
6234
7234
8234
1934
1834
1734
1634
1234
2034
2019
1834
8009
2994
2874
2004
9268
7268
9278
9268
9018
9268
5268
8968
8718
7668
6508
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9268
9267
9266
9265
9264
9263
9262
9876
9877
9878
9879
1876
2876
3876
4876
1876
2876
3876
4876
1876
2876
3876
4876
9811
9822
9833
9844
4444
5555
6666
7777
8888
8080
8181
 

MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:Write a query to find all employees where first names are in upper case.
Next:Write a query to get the last word of the street address.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.