w3resource

SQL SORTING and FILTERING on HR Database: Display the first and last name, and department number for all employees whose last name is "McEwen"

SQL SORTING and FILTERING on HR Database: Exercise-3 with Solution

3. From the following table, write a SQL query to find those employees whose last name is "McEwen". Return first name, last name and department ID.

Sample table: employees


Sample Solution:

SELECT first_name, last_name, department_id
 FROM employees
  WHERE last_name = 'McEwen';

Sample Output:

 first_name | last_name | department_id
------------+-----------+---------------
 Allan      | McEwen    |            80
(1 row)

Relational Algebra Expression:

Relational Algebra Expression: Display the first and last name, and department number for all employees whose last name is 'McEwen'.

Relational Algebra Tree:

Relational Algebra Tree: Display the first and last name, and department number for all employees whose last name is 'McEwen'.

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the first and last name, and department number for all employees whose last name is

Rows:

Query visualization of Display the first and last name, and department number for all employees whose last name is

Cost:

Query visualization of Display the first and last name, and department number for all employees whose last name is

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to find those employees whose salary is higher than 8000. Return first name, last name and department number and salary.
Next: From the following table, write a SQL query to find those employees who have no department number. Return employee_id, first_name, last_name, email,phone_number,hire_date, job_id, salary,commission_pct,manager_id and department_id.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS