78. Employees With Confirmed Salary Records

An HR system stores employee information and salary details in separate tables. Only employees who have both personal details and salary records are considered valid for payroll processing.

Table: Employees

╔═════════════╦══════════╗
ā•‘ Column Name ā•‘   Type   ā•‘
╠═════════════╬══════════╣
ā•‘ employee_id ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘    name     ā•‘ varchar  ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
  • employee_id is the primary key.
  • Each row represents an employee.

Table: Salaries

╔═════════════╦══════════╗
ā•‘ Column Name ā•‘   Type   ā•‘
╠═════════════╬══════════╣
ā•‘ employee_id ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘   salary    ā•‘   int    ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
  • employee_id is the primary key.
  • Each row represents a salary entry.

Write an SQL query to return only those employees who have a salary record.

For each qualifying employee, return:

  • employee_id
  • name
  • salary

The result can be returned in any order.

Example 1:

Example:

Input:

Employees:

╔═════════════╦══════════╗
ā•‘ employee_id ā•‘   name   ā•‘
╠═════════════╬══════════╣
ā•‘      1      ā•‘  Aarav   ā•‘
║─────────────┼──────────║
ā•‘      2      ā•‘   Neha   ā•‘
║─────────────┼──────────║
ā•‘      3      ā•‘  Rohan   ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Salaries:

╔═════════════╦══════════╗
ā•‘ employee_id ā•‘  salary  ā•‘
╠═════════════╬══════════╣
ā•‘      1      ā•‘  50000   ā•‘
║─────────────┼──────────║
ā•‘      3      ā•‘  60000   ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Output:

╔═════════════╦══════════╦══════════╗
ā•‘ employee_id ā•‘   name   ā•‘  salary  ā•‘
╠═════════════╬══════════╬══════════╣
ā•‘      1      ā•‘  Aarav   ā•‘  50000   ā•‘
║─────────────┼──────────┼──────────║
ā•‘      3      ā•‘  Rohan   ā•‘  60000   ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Explanation

Neha does not have a salary record, so she is excluded.

Only employees present in both tables appear in the output.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Ā 
Test Case

Input:

Employees
Salaries