w3resource

PostgreSQL Restricting and Sorting Data: Select all information of employees against some specific last name


11. Write a query to select all information of employees whose last name is either 'JONES' or 'BLAKE' or 'SCOTT' or 'KING' or 'FORD'.

Sample Solution:

Code:

SELECT * 
FROM employees 
WHERE last_name IN('Jones', 'Blake', 'Scott', 'King', 'Ford');

Sample table: employees


Output:

pg_exercises=# SELECT *
pg_exercises-# FROM employees
pg_exercises-# WHERE last_name IN('Jones', 'Blake', 'Scott', 'King', 'Ford');


 employee_id | first_name | last_name | email  |    phone_number    | hire_date  |  job_id  |  salary  | commission_pct | manager_id | department_id
-------------+------------+-----------+--------+--------------------+------------+----------+----------+----------------+------------+---------------
         100 | Steven     | King      | SKING  | 515.123.4567       | 1987-06-17 | AD_PRES  | 24000.00 |           0.00 |          0 |            90
         156 | Janette    | King      | JKING  | 011.44.1345.429268 | 1987-08-12 | SA_REP   | 10000.00 |           0.35 |        146 |            80
         195 | Vance      | Jones     | VJONES | 650.501.4876       | 1987-09-20 | SH_CLERK |  2800.00 |           0.00 |        123 |            50
(3 rows)

Relational Algebra Expression:

Relational Algebra Expression: Select all information of employees against some specific last name.

Relational Algebra Tree:

Relational Algebra Tree: Select all information of employees against some specific last name.

Practice Online


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

Previous: Write a query to display the jobs/designations available in the employees table.
Next: PostgreSQL Aggregate Functions and Group By- Exercises, Practice, Solution

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.