Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
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.

Previous: Write a query to get the first names after removing all the leading and trailing blanks of all the employees from employees table.
Next: Write a query to check whether the first_name column of the employees table containing any number.

What is the difficulty level of this exercise?