Delete Duplicate Employee Records
Updated
Problem statement
The table employees holds employee records. Because of a data entry bug, the same record was sometimes stored more than once: two rows are copies of the same record when they have the same emp_id and the same name. Each stored row has its own row_id.
Delete the duplicates: for each record, keep only the copy with the smallest row_id and remove the others. Rows that are not repeated stay as they are.
Your answer is checked on the rows that remain. Write one read-only SELECT query (a CTE is fine) in SQL, or return a DataFrame in Pandas, that returns exactly the remaining rows with the columns row_id, emp_id, and name, sorted by row_id from smallest to largest. The input table itself is not changed.
| Column | Meaning |
|---|---|
row_id | Unique number of the stored row |
emp_id | Employee ID |
name | Employee name |
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
employees
Employee records. The same employee record (emp_id and name) may have been stored more than once.
| Column | Type | Nullable | Description |
|---|---|---|---|
| row_idPK | Integer | No | Unique number of the stored row. |
| emp_id | Integer | No | Employee ID. |
| name | Text | No | Employee name. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| row_id | Integer | No | — |
| emp_id | Integer | No | — |
| name | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
employeeshas at most500rows.row_idis unique;row_idandemp_idare integers between1and10^6.namehas1to30English letters. Two names in the table never differ only in upper or lower case.- No column contains
NULL.
More Infosys Onsite Interview questions
- Minimum Coins for a TargetONSITE INTERVIEW · Seen Nov 2026
- Find Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
- Minimum Insertion Steps to Make a String PalindromeONSITE INTERVIEW · Seen Nov 2026
- Maximize the Even-Odd Index Product GapONSITE INTERVIEW · Seen Oct 2026
- Minimum Nonadjacent Flips for an Alternating Binary StringONSITE INTERVIEW · Seen Oct 2026
- Tenth-Highest Distinct SalaryONSITE INTERVIEW · Seen Oct 2026
- Assign Cookies With Matching ParityONSITE INTERVIEW · Seen Sep 2026
- Count Equal Code Pairs Within Distance KONSITE INTERVIEW · Seen Sep 2026
- Daily Successful Transactions Per DepartmentONSITE INTERVIEW · Seen Sep 2026
- Detect Substring In Any RotationONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Records Created or Updated in a Time WindowPelatro · ONSITE INTERVIEW
- Top Ten Employee SalariesSolytics Partners · ONSITE INTERVIEW
- Latest New JobSphere · ONSITE INTERVIEW
- Employees Whose Manager Left the CompanyZS · ONSITE INTERVIEWZS interview questions
- Employees Above Average SalaryJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Retrieve Every Student RecordLSEG · ONSITE INTERVIEWLSEG interview questions
- Combine Winner and Loser NamesAmazon · ONSITE INTERVIEW
- Conditionally Insert or Update RecordsKlaviyo · ONSITE INTERVIEWKlaviyo interview questions
- Employees with Matching DepartmentsAMD · ONSITE INTERVIEWAMD interview questions
- New-User Devices That Opened an AppMicrosoft · ONSITE INTERVIEWMicrosoft interview questions