FastPrepFind Rows Common to Two Tables

Find Rows Common to Two Tables

Salesforce logoSalesforce● EasyNEW GRADPHONE SCREEN

Problem statement

Find the intersection of left_records and right_records. Both tables contain the columns record_id and record_text.

Return every complete row that appears in both tables. A match requires both columns to be equal. Return each common row exactly once, even when an input contains duplicates. Output the columns record_id, record_text, ordered by record_id ascending and then record_text ascending.

For this exercise, assume the two-column non-null schema, full-row equality, distinct-row semantics, ordering and bounds below. These are practice conventions completing the reported two-table intersection task.

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

ColumnTypeNullableDescription
record_idIntegerNo—
record_textTextNo—

right_records

ColumnTypeNullableDescription
record_idIntegerNo—
record_textTextNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
record_idIntegerNo—
record_textTextNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Each table contains between 0 and 1000 rows; duplicate rows are allowed.
  • -1000000 <= record_id <= 1000000.
  • record_text contains 1 to 30 lowercase English letters.
  • Neither column contains null values.

More Salesforce problems

See Salesforce hiring insights