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.