w3resource

PostgreSQL String() Function: Find all the employees which first name contains all the uppercase letter


8. Write a query to find all the employees which first name contains all the uppercase letter.

Sample Solution:

Code:

-- This SQL query retrieves all columns from the employees table where the first name is in uppercase.

SELECT * -- Selects all columns from the employees table
FROM employees -- Specifies the table from which to retrieve data, in this case, the employees table
WHERE first_name = UPPER(first_name); -- Filters the rows to include only those where the first name is in uppercase

Explanation:

  • This SQL query retrieves data from the employees table.
  • The SELECT * statement selects all columns from the employees table.
  • The FROM clause specifies the table from which to retrieve the data, which is the employees table.
  • The WHERE clause filters the rows to include only those where the first_name column is equal to its uppercase version.
  • The UPPER() function converts the first_name column to uppercase.
  • The condition first_name = UPPER(first_name) checks if the first_name column is equal to its uppercase version, indicating that the first name is already in uppercase.
  • The result set will contain all columns for rows where the first name is in uppercase.

Sample table: employees


Output:

pg_exercises=# SELECT *
pg_exercises-# FROM employees
pg_exercises-# WHERE first_name = UPPER(first_name);

 employee_id | first_name | last_name |     email     | phone_number | hire_date  |  job_id  | salary  | commission_pct | manager_id | department_id
-------------+------------+-----------+---------------+--------------+------------+----------+---------+----------------+------------+---------------
         132 | TJ         | Olson     | not available | 650.123.8234 | 1987-07-19 | ST_CLERK | 2130.00 |           0.10 |        121 |            50
(1 row)

(END)

Practice Online


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

Previous: Write a query to get the employee id, email id to discard the last three characters.
Next: Write a query to extract the last four characters of phone numbers.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/postgresql-exercises/string/postgresql-string-exercise-8.php