Materials Experiment Records
Beginner Mode
Scenario
You are a materials engineer with two tables: one tracking lab experiments and another cataloging available materials.
Task
Write a Snowflake SQL query that:
- Performs a full outer join between
{{ ref("experiments") }}and{{ ref("materials") }}onmaterial_id - Uses
COALESCEto produce a single non-nullmaterial_idcolumn from both sides - Returns
experiment_id,experiment_date,experiment_resultsfrom the experiments side andmaterial_name,material_typefrom the materials side
Schema
experiments
| Column | Type | Description |
|---|---|---|
| experiment_id | Integer | Unique experiment identifier |
| material_id | Integer | Foreign key to materials |
| experiment_date | String | Date the experiment was conducted |
| experiment_results | Float | Numeric result of the experiment |
materials
| Column | Type | Description |
|---|---|---|
| material_id | Integer | Unique material identifier |
| material_name | String | Name of the material |
| material_type | String | Category of the material |
Example
experiments:
| experiment_id | material_id | experiment_date | experiment_results |
|---|---|---|---|
| 1 | 201 | 2024-03-01 | 5.4 |
| 2 | 202 | 2024-03-02 | 6.1 |
| 3 | 203 | 2024-03-03 | 4.8 |
| 4 | 201 | 2024-03-04 | 5.9 |
materials:
| material_id | material_name | material_type |
|---|---|---|
| 201 | Graphene | Polymer |
| 202 | Kevlar | Composite |
| 204 | Titanium | Metal |
Expected Output:
| experiment_date | experiment_id | experiment_results | material_id | material_name | material_type |
|---|---|---|---|---|---|
| 2024-03-01 | 1 | 5.4 | 201 | Graphene | Polymer |
| 2024-03-02 | 2 | 6.1 | 202 | Kevlar | Composite |
| 2024-03-03 | 3 | 4.8 | 203 | NULL | NULL |
| 2024-03-04 | 4 | 5.9 | 201 | Graphene | Polymer |
| NULL | NULL | NULL | 204 | Titanium | Metal |
Note: Experiment 3 used material 203 which has no entry in the materials table (NULLs for material columns). Material 204 has no experiments (NULLs for experiment columns). The output always shows a non-null material_id by taking the available value from whichever side has it.
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Samsung