Combine Winner and Loser Names
Updated
Problem statement
The winner table and the loser table each have one row per person: an id and a name.
Write a query that puts the names from both tables into one output column called name. Show each name only once, even if it is in both tables or appears more than once in the same table.
Return the rows in any order.
Interview follow-up
Write the query once with UNION and once with UNION ALL, and explain how the two results differ. Only the version above, with each name once, is checked.
Table schema
MySQLPostgreSQLPandas
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.
winner
One row per winner.
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| name | Text | No | — |
loser
One row per loser.
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| name | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| name | Text | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- Each table has from
0to10^5rows. idis unique within each table, and1 <= id <= 10^9. The sameidin the two tables does not mean the same person.- No column is
NULL. - Each
namehas 1 to 20 English letters: one uppercase letter followed by lowercase letters.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
- 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
- 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