Top 3 Earners

EasySQLDatabaseSorting

Description

Write a SQL query to return the name and salary of the three highest-paid employees, ordered by salary descending. **Output columns (in order):** name, salary

Table:employees
ColumnType
idINT
nameTEXT
salaryINT

Examples

Input:CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'A',100),(2,'B',300),(3,'C',200),(4,'D',400);
Output:D|400 B|300 C|200
Explanation:

Ordering by pay from high to low and keeping the first three yields the top earners.

Input:CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'A',50),(2,'B',60);
Output:B|60 A|50
Explanation:

Ordering by pay from high to low and keeping the first three yields the top earners.

Input:CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'Solo',999);
Output:Solo|999
Explanation:

Ordering by pay from high to low and keeping the first three yields the top earners.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.