w3resource

MySQL String Exercises: Get the details of the employees where the length of the first name greater than or equal to 8

MySQL String: Exercise-3 with Solution

Write a query to get the details of the employees where the length of the first name greater than or equal to 8.

Sample table: employees


Output:

SELECT * 
FROM employees
WHERE LENGTH(first_name) >= 8;

Sample Output:

 employee_id | first_name  | last_name |  email  |    phone_number    | hire_date  |   job_id   |  salary  | commission_pct | manager_id | department_id
-------------+-------------+-----------+---------+--------------------+------------+------------+----------+----------------+------------+---------------
         103 | Alexander   | Hunold    | AHUNOLD | 590.423.4567       | 2006-01-03 | IT_PROG    |  9000.00 |           0.00 |        102 |            60
         112 | Jose Manuel | Urman     | JMURMAN | 515.124.4469       | 2006-03-07 | FI_ACCOUNT |  7800.00 |           0.00 |        108 |           100
         115 | Alexander   | Khoo      | AKHOO   | 515.127.4562       | 2003-05-18 | PU_CLERK   |  3100.00 |           0.00 |        114 |            30
         153 | Christopher | Olsen     | COLSEN  | 011.44.1344.498718 | 2006-03-30 | SA_REP     |  8000.00 |           0.20 |        145 |            80
         163 | Danielle    | Greene    | DGREENE | 011.44.1346.229268 | 2007-03-19 | SA_REP     |  9500.00 |           0.15 |        147 |            80
         169 | Harrison    | Bloom     | HBLOOM  | 011.44.1343.829268 | 2006-03-23 | SA_REP     | 10000.00 |           0.20 |        148 |            80
         172 | Elizabeth   | Bates     | EBATES  | 011.44.1343.529268 | 2007-03-24 | SA_REP     |  7300.00 |           0.15 |        148 |            80
         176 | Jonathon    | Taylor    | JTAYLOR | 011.44.1644.429265 | 2006-03-24 | SA_REP     |  8600.00 |           0.20 |        149 |            80
         178 | Kimberely   | Grant     | KGRANT  | 011.44.1644.429263 | 2007-05-24 | SA_REP     |  7000.00 |           0.15 |        149 |             0
         189 | Jennifer    | Dilly     | JDILLY  | 650.505.2876       | 2005-08-13 | SH_CLERK   |  3600.00 |           0.00 |        122 |            50
         200 | Jennifer    | Whalen    | JWHALEN | 515.123.4444       | 2003-09-17 | AD_ASST    |  4400.00 |           0.00 |        101 |            10
(11 rows)

MySQL Code Editor:

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

Previous: Write a query to update the portion of the phone_number in the employees table, within the phone number the substring '124' will be replaced by '999'.
Next: Write a query to display leading zeros before maximum and minimum salary.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.