w3resource

SQL Exercises: List the employees that work in the department 57

SQL Basic Select Statement: Exercise-33 with Solution.

From the following table, write a SQL query to retrieve the details of the employees who work in the department 57. Return emp_idno, emp_fname, emp_lname and emp_dept.

Sample table: emp_details

 EMP_IDNO EMP_FNAME       EMP_LNAME         EMP_DEPT
--------- --------------- --------------- ----------
   127323 Michale         Robbin                  57
   526689 Carlos          Snares                  63
   843795 Enric           Dosio                   57
   328717 Jhon            Snares                  63
   444527 Joseph          Dosni                   47
   659831 Zanifer         Emily                   47
   847674 Kuleswar        Sitaraman               57
   748681 Henrey          Gabriel                 47
   555935 Alex            Manuel                  57
   539569 George          Mardy                   27
   733843 Mario           Saule                   63
   631548 Alan            Snappy                  27
   839139 Maria           Foster                  57

 

Sample Solution:

-- This query selects all columns from the 'emp_details' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'emp_details').
FROM emp_details
-- Filters the rows to only include those where the 'emp_dept' column has the value 57.
WHERE emp_dept = 57;

Output of the Query:

emp_idno	emp_fname	emp_lname	emp_dept
839139		Maria		Foster		57
127323		Michale		Robbin		57
843795		Enric		Dosio		57
847674		Kuleswar	Sitaraman	57
555935		Alex		Manuel		57

Code Explanation:

This SQL statement selects all columns from the table named 'emp_details' where the emp_dept is 57. It returns all the rows that have the value 57 in the emp_dept column.

Relational Algebra Expression:

Relational Algebra Expression: Display all the data of employees that work in the department 57.

Relational Algebra Tree:

Relational Algebra Tree: Display all the data of employees that work in the department 57.

Practice Online


Query Visualization:

Duration:

Query visualization of Display all the data of employees that work in the department 57 - Duration

Rows:

Query visualization of Display all the data of employees that work in the department 57 - Rows

Cost:

Query visualization of Display all the data of employees that work in the department 57 - Cost

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

Previous Python Exercises: Find the data of employees whose last name is 'Snares'.
Next Python Exercise: SQL Boolean and Relational Operators Exercises Home

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.