Modules
Data Analyst
Data Engineer
Product Data Scientist
AI Engineer
Machine Learning Engineer
Prompt Engineer
Write a SQL query to identify the first order placed by each user. If a user made multiple orders on their first day of purchase, only display the product with the lowest alphabetical order.
Your query should return the user_id, the corresponding order_id, and the name of the product ordered.
orders table:
| Column Name | Description |
|---|---|
| order_id | Unique identifier for each order. |
| user_id | Identifier of the user who placed the order. |
| product_id | Identifier of the product ordered. |
| order_date | Date when the order was placed. |
products table:
| Column Name | Description |
|---|---|
| id | Unique identifier for each product. |
| product_name | Name of the product. |
| department_id | Identifier of the department to which the product belongs. |
| user_id | order_id | product_name |
|---|---|---|
| 1 | 1 | Chips |
| 2 | 3 | Soda |
| 3 | 4 | Milk |
Write a SQL query to identify the first order placed by each user. If a user made multiple orders on their first day of purchase, only display the product with the lowest alphabetical order.
Your query should return the user_id, the corresponding order_id, and the name of the product ordered.
orders table:
| Column Name | Description |
|---|---|
| order_id | Unique identifier for each order. |
| user_id | Identifier of the user who placed the order. |
| product_id | Identifier of the product ordered. |
| order_date | Date when the order was placed. |
products table:
| Column Name | Description |
|---|---|
| id | Unique identifier for each product. |
| product_name | Name of the product. |
| department_id | Identifier of the department to which the product belongs. |
| user_id | order_id | product_name |
|---|---|---|
| 1 | 1 | Chips |
| 2 | 3 | Soda |
| 3 | 4 | Milk |