Find Rows Common to Two Tables
Updated
Problem statement
Find the rows that appear in both left_records and right_records. Both tables have the columns record_id and record_text.
Return every row that appears in both tables. Two rows match only when both columns are equal. Return each common row once, even if an input has duplicates. Output the columns record_id and record_text, sorted by record_id ascending and then by record_text ascending.
Assume that neither column is ever null.
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.
left_records
| Column | Type | Nullable | Description |
|---|---|---|---|
| record_id | Integer | No | — |
| record_text | Text | No | — |
right_records
| Column | Type | Nullable | Description |
|---|---|---|---|
| record_id | Integer | No | — |
| record_text | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| record_id | Integer | No | — |
| record_text | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Each table contains between
0and1000rows; duplicate rows are allowed. -1000000 <= record_id <= 1000000.record_textcontains1to30lowercase English letters.- Neither column contains null values.
More Salesforce Phone Screen questions
- Detect a Cycle in a Linked ListPHONE SCREEN · Seen Oct 2026
- Merge Two Sorted Linked ListsPHONE SCREEN · Seen Oct 2026
- Minimum Window of Required WordsPHONE SCREEN · Seen Aug 2026
- Permutations of Unique CharactersPHONE SCREEN · Seen Aug 2026
- Minimum Window SubstringPHONE SCREEN · Seen Aug 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
Similar questions at other companies
- Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Swap Two Gender ValuesInfosys · PHONE SCREENInfosys interview questions
- Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions
- Customer Order Count Distribution by CountryApple · PHONE SCREENApple interview questions
- Employees Earning More Than Their ManagerMygate · PHONE SCREENMygate interview questions
- Classify Tree Nodes with SQLOracle · PHONE SCREENOracle interview questions