Left and Right Join Results
Problem statement
The tables left_items and right_items each contain uniquely identified rows and a shared join_key.
Return the row-level output of both left_items LEFT JOIN right_items and left_items RIGHT JOIN right_items, using equality on join_key.
Label rows from the first join as LEFT and rows from the second join as RIGHT. Preserve every matching row combination. For an unmatched row, return NULL for every column from the missing side.
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_items
Rows on the left side of both joins.
| Column | Type | Nullable | Description |
|---|---|---|---|
| left_idPK | Integer | No | — |
| join_key | Integer | No | — |
| left_value | Text | No | — |
right_items
Rows on the right side of both joins.
| Column | Type | Nullable | Description |
|---|---|---|---|
| right_idPK | Integer | No | — |
| join_key | Integer | No | — |
| right_value | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| join_type | Text | No | — |
| join_key | Integer | No | — |
| left_id | Integer | Yes | — |
| left_value | Text | Yes | — |
| right_id | Integer | Yes | — |
| right_value | Text | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
left_idis unique inleft_items, andright_idis unique inright_items.join_keyis non-null; multiple rows may share the same key.- Return columns in this order:
join_type,join_key,left_id,left_value,right_id,right_value. - Sort
LEFTrows beforeRIGHTrows, then byjoin_key,left_id, andright_idascending, with a missing ID after non-null IDs.