w3resource

PostgreSQL Basic SELECT Statement: Get the length of the name, including first_name and last_name of all the employees


16. Write a query to get the first name, last name and the length of the name, including first_name and last_name of all the employees from employees table.

Sample Solution:

Code:

SELECT first_name,last_name, 
LENGTH(first_name)+LENGTH(last_name)  "Length of  Names" 
FROM employees;

Sample table: employees


Output:

pg_exercises=# SELECT first_name,last_name,
pg_exercises-# LENGTH(first_name)+LENGTH(last_name)  "Length of  Names"
pg_exercises-# FROM employees;
 first_name  |  last_name  | Length of  Names
-------------+-------------+------------------
 Steven      | King        |               10
 Neena       | Kochhar     |               12
 Lex         | De Haan     |               10
 Alexander   | Hunold      |               15
 Bruce       | Ernst       |               10
 David       | Austin      |               11
 Valli       | Pataballa   |               14
 ....
 Alexander   | Khoo        |               13
 Shelli      | Baida       |               11
 Sigal       | Tobias      |               11
 Guy         | Himuro      |                9
 Karen       | Colmenares  |               15
 Matthew     | Weiss       |               12
 ....
 Steven      | Markle      |               12
 Laura       | Bissot      |               11
 Mozhe       | Atkinson    |               13
 James       | Marlow      |               11
 TJ          | Olson       |                7
 ....
 Renske      | Ladwig      |               12
 Stephen     | Stiles      |               13
 John        | Seo         |                7
 Joshua      | Patel       |               11
 Trenna      | Rajs        |               10
...
 Hermann     | Baer        |               11
 Shelley     | Higgins     |               14
 William     | Gietz       |               12
(107 rows)

Practice Online



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

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming