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 the first name and last name of each employee, along with the name and sanction amount for their department

SQL JOINS: Exercise-27 with Solution

From the following tables write a SQL query to display the first and last names of each employee, as well as the department name and sanction amount.

Sample table:emp_department


Sample table: emp_details


Sample Solution:

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

Output of the Query:

First Name	Last Name	Department	Amount Allotted
Alan		Snappy		RD		55000
Maria		Foster		IT		65000
Michale		Robbin		IT		65000
Carlos		Snares		Finance		15000
Enric		Dosio		IT		65000
Jhon		Snares		Finance		15000
Joseph		Dosni		HR		240000
Zanifer		Emily		HR		240000
Kuleswar	Sitaraman	IT		65000
Henrey		Gabriel		HR		240000
Alex		Manuel		IT		65000
George		Mardy		RD		55000
Mario		Saule		Finance		15000

Practice Online


Query Visualization:

Duration:

Query visualization of Display the first name and last name of each employee, along with the name and sanction amount for their department - Duration

Rows:

Query visualization of Display the first name and last name of each employee, along with the name and sanction amount for their department - Rows

Cost:

Query visualization of Display the first name and last name of each employee, along with the name and sanction amount for 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 display all the data of employees including their department.
Next: From the following tables write a SQL query to find the departments with a budget more than Rs. 50000 and display the first name and last name of employees.

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