Join Employee, Department and Salary Tables to Report HRA for Bangalore and Chennai Staff

Quick Overview

Write a SQL query that joins employee, department and salary tables and returns the house rent allowance for staff whose department is located in Bangalore or Chennai. It tests multi-table inner joins, filtering on a joined column, and keeping joins from duplicating rows.

Join Employee, Department and Salary Tables to Report HRA for Bangalore and Chennai Staff

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Join `EmployeeInfo`, `DeptInfo` and `SalaryInfo`, and return `EmpID`, `Name`, `DeptName` and `HRA` (house rent allowance) for every employee whose department is located in Bangalore or Chennai. Order the result by `EmpID` ascending. ```hint Where the filter lives The city is a property of the department, and the allowance is stored apart from the employee. Work out which key links each of those tables to `EmployeeInfo` before you write the filter. ``` ### Input Table(s) `EmployeeInfo` | Column | Type | Meaning | |---|---|---| | EmpID | INT | Employee id | | Name | VARCHAR | Employee name | | DeptID | INT | The employee's department, references `DeptInfo.DeptID` | Primary key: `EmpID`. `DeptInfo` | Column | Type | Meaning | |---|---|---| | DeptID | INT | Department id | | DeptName | VARCHAR | Department name | | Location | VARCHAR | City where the department is located, such as 'Bangalore', 'Chennai', 'Mumbai' or 'Delhi' | Primary key: `DeptID`. `SalaryInfo` | Column | Type | Meaning | |---|---|---| | EmpID | INT | Employee id, references `EmployeeInfo.EmpID` | | HRA | INT | The employee's house rent allowance | Primary key: `EmpID` (exactly one salary row per employee). ### Output Contract Columns in this order: `EmpID`, `Name`, `DeptName`, `HRA`. Return one row per qualifying employee, ordered by `EmpID` ascending. `EmpID` is unique, so the order is unique. No rounding is needed. ### Example Input `EmployeeInfo`: | EmpID | Name | DeptID | |---|---|---| | 1 | Asha | 10 | | 2 | Ravi | 20 | | 3 | Meena | 30 | | 4 | Karan | 10 | | 5 | Priya | 40 | Input `DeptInfo`: | DeptID | DeptName | Location | |---|---|---| | 10 | Finance | Bangalore | | 20 | Marketing | Mumbai | | 30 | Engineering | Chennai | | 40 | Operations | Delhi | Input `SalaryInfo`: | EmpID | HRA | |---|---| | 1 | 12000 | | 2 | 9000 | | 3 | 15000 | | 4 | 11000 | | 5 | 8000 | Expected output: | EmpID | Name | DeptName | HRA | |---|---|---|---| | 1 | Asha | Finance | 12000 | | 3 | Meena | Engineering | 15000 | | 4 | Karan | Finance | 11000 | Asha and Karan work in Finance (Bangalore) and Meena works in Engineering (Chennai), so they are returned. Ravi's department is in Mumbai and Priya's is in Delhi, so both are left out. ### Constraints and Clarifications - There are at most 10,000 employees. - Each `EmpID` is unique and maps to exactly one `SalaryInfo` row. - Each `DeptID` in `DeptInfo` is unique. - `Location` holds plain city names. Match 'Bangalore' and 'Chennai' exactly as written. - An employee whose department is missing from `DeptInfo`, or whose department has a NULL `Location`, is not located in either city and is left out.

Overview: Write a SQL query that joins employee, department and salary tables and returns the house rent allowance for staff whose department is located in Bangalore or Chennai. It tests multi-table inner joins, filtering on a joined column, and keeping joins from duplicating rows.

Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Join EmployeeInfo, DeptInfo and SalaryInfo, and return EmpID, Name, DeptName and HRA (house rent allowance) for every employee whose department is located in Bangalore or Chennai. Order the result by EmpID ascending.

Input Table(s)

EmployeeInfo

ColumnTypeMeaning
EmpIDINTEmployee id
NameVARCHAREmployee name
DeptIDINTThe employee's department, references DeptInfo.DeptID

Primary key: EmpID.

DeptInfo

ColumnTypeMeaning
DeptIDINTDepartment id
DeptNameVARCHARDepartment name
LocationVARCHARCity where the department is located, such as 'Bangalore', 'Chennai', 'Mumbai' or 'Delhi'

Primary key: DeptID.

SalaryInfo

ColumnTypeMeaning
EmpIDINTEmployee id, references EmployeeInfo.EmpID
HRAINTThe employee's house rent allowance

Primary key: EmpID (exactly one salary row per employee).

Output Contract

Columns in this order: EmpID, Name, DeptName, HRA. Return one row per qualifying employee, ordered by EmpID ascending. EmpID is unique, so the order is unique. No rounding is needed.

Example

Input EmployeeInfo:

EmpIDNameDeptID
1Asha10
2Ravi20
3Meena30
4Karan10
5Priya40

Input DeptInfo:

DeptIDDeptNameLocation
10FinanceBangalore
20MarketingMumbai
30EngineeringChennai
40OperationsDelhi

Input SalaryInfo:

EmpIDHRA
112000
29000
315000
411000
58000

Expected output:

EmpIDNameDeptNameHRA
1AshaFinance12000
3MeenaEngineering15000
4KaranFinance11000

Asha and Karan work in Finance (Bangalore) and Meena works in Engineering (Chennai), so they are returned. Ravi's department is in Mumbai and Priya's is in Delhi, so both are left out.

Constraints and Clarifications

  • There are at most 10,000 employees.
  • Each EmpID is unique and maps to exactly one SalaryInfo row.
  • Each DeptID in DeptInfo is unique.
  • Location holds plain city names. Match 'Bangalore' and 'Chennai' exactly as written.
  • An employee whose department is missing from DeptInfo , or whose department has a NULL Location , is not located in either city and is left out.