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

SQL Exercises: Display all the data of employees including their department

SQL JOINS: Exercise-26 with Solution

From the following tables write a SQL query to display all the data of employees including their department.

Sample table:emp_department


Sample table: emp_details


Sample Solution:

SELECT emp_idno, A.emp_fname AS "First Name", emp_lname AS "Last Name",
    B.dpt_name AS "Department", emp_dept, dpt_code,  dpt_allotment
     FROM emp_details A 
      INNER JOIN emp_department B
        ON A.emp_dept = B.dpt_code;

Output of the Query:

emp_idno	First Name	Last Name	Department	emp_dept	dpt_code	dpt_allotment
631548		Alan		Snappy		RD		27		27		55000
839139		Maria		Foster		IT		57		57		65000
127323		Michale		Robbin		IT		57		57		65000
526689		Carlos		Snares		Finance		63		63		15000
843795		Enric		Dosio		IT		57		57		65000
328717		Jhon		Snares		Finance		63		63		15000
444527		Joseph		Dosni		HR		47		47		240000
659831		Zanifer		Emily		HR		47		47		240000
847674		Kuleswar	Sitaraman	IT		57		57		65000
748681		Henrey		Gabriel		HR		47		47		240000
555935		Alex		Manuel		IT		57		57		65000
539569		George		Mardy		RD		27		27		55000
733843		Mario		Saule		Finance		63		63		15000

Practice Online


Query Visualization:

Duration:

Query visualization of Display all the data of employees including their department - Duration

Rows:

Query visualization of Display all the data of employees including their department - Rows

Cost:

Query visualization of Display all the data of employees including their department - Cost

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

Previous: From the following tables write a SQL query to find the most expensive product of each company. Return pro_name, pro_price and com_name.
Next: From the following tables write a SQL to display the first name and last name of each employee, along with the name and sanction amount for their department.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

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