Hackerrank - SQL - Name of Employees
Mr Punk da Silva

Mr Punk da Silva @mrpunkdasilva

About: I'm a Brazilian Software Engineer passionate about creating elegant solutions for complex problems. I specialize in full-stack development with a focus on clean code, solid architecture, and exception

Location:
In my mind
Joined:
Jul 19, 2023

Hackerrank - SQL - Name of Employees

Publish Date: Jul 13
0 0

Problem Description

Write a query that prints a list of employee names (i.e.: the name attribute) from the EMPLOYEE table in alphabetical order.

Input Format

The EMPLOYEE table contains employee data and is described as follows:

Column Type
ID INTEGER
NAME STRING
SALARY INTEGER

where ID is the employee ID, NAME is the employee name, and SALARY is the employee monthly salary.

Solution Approach

Use a simple SELECT statement to retrieve only the NAME column from the EMPLOYEE table, and order the results alphabetically using ORDER BY.

Step-by-Step Explanation

  1. Start with the SELECT statement to retrieve only the NAME column:
   SELECT NAME
Enter fullscreen mode Exit fullscreen mode
  1. Specify the table to query from:
   FROM EMPLOYEE
Enter fullscreen mode Exit fullscreen mode
  1. Add the ORDER BY clause to sort the names alphabetically:
   ORDER BY NAME ASC
Enter fullscreen mode Exit fullscreen mode
  1. The final query:
   SELECT NAME
   FROM EMPLOYEE
   ORDER BY NAME ASC
   ;
Enter fullscreen mode Exit fullscreen mode

Expected Output

The query will return a single column containing all employee names from the EMPLOYEE table, sorted in alphabetical order (A to Z).

Repo https://github.com/mrpunkdasilva/hackerrank/tree/main/sql/basic/name-of-employees

Comments 0 total

    Add comment