Distinct Departments
EasySQLDatabaseHash TableSorting
Description
Write a SQL query to return each distinct department name, ordered alphabetically. **Output columns (in order):** department
Table:
employees| Column | Type |
|---|---|
| id | INT |
| name | TEXT |
| department | TEXT |
Examples
Input:
CREATE TABLE employees (id INT, name TEXT, department TEXT); INSERT INTO employees VALUES (1,'A','Eng'),(2,'B','Sales'),(3,'C','Eng');Output:
Eng
SalesExplanation:
Duplicate department names are collapsed so each one appears once, sorted alphabetically.
Input:
CREATE TABLE employees (id INT, name TEXT, department TEXT); INSERT INTO employees VALUES (1,'A','HR'),(2,'B','HR');Output:
HRExplanation:
Duplicate department names are collapsed so each one appears once, sorted alphabetically.
Input:
CREATE TABLE employees (id INT, name TEXT, department TEXT); INSERT INTO employees VALUES (1,'A','Z'),(2,'B','Y'),(3,'C','X');Output:
X
Y
ZExplanation:
Duplicate department names are collapsed so each one appears once, sorted alphabetically.
Constraints
- •
Use standard SQL (SQLite).