MySQL String Exercises: Display the first name starts with specific letters
MySQL String: Exercise-14 with Solution
Write a query that displays the first name and the length of the first name for all employees whose name starts with the letters 'A', 'J' or 'M'. Give each column an appropriate label. Sort the results by the employees' first names.
Sample table: employees
Code:
SELECT first_name "Name",
LENGTH(first_name) "Length"
FROM employees
WHERE first_name LIKE 'J%'
OR first_name LIKE 'M%'
OR first_name LIKE 'A%'
ORDER BY first_name ;
Sample Output:
Name Length Adam 4 Alana 5 Alberto 7 Alexander 9 Alexander 9 Alexis 6 Allan 5 Alyssa 6 Amit 4 Anthony 7 Jack 4 James 5 James 5 Janette 7 Jason 5 Jean 4 Jennifer 8 Jennifer 8 John 4 John 4 John 4 Jonathon 8 Jose Manuel 11 Joshua 6 Julia 5 Julia 5 Martha 6 Mattea 6 Matthew 7 Michael 7 Michael 7 Mozhe 5
MySQL Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a query to display the length of first name for employees where last name contain character 'c' after 2nd position.
Next:Write a query to display the first name and salary for all employees. Format the salary to be 10 characters long, left-padded with the $ symbol.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework