Order management systems store customer references as foreign key IDs for efficiency, but support agents and operations teams need human-readable names when reviewing orders. Joining orders to the customers table at query time is the standard pattern for enriching transactional data with descriptive attributes. Using the orders and customers tables, return order_id, customer_name, amount, and created_at for every order, ordered by created_at.
customers
| column | type |
|---|---|
| id | INTEGER |
| name | TEXT |
| TEXT |
orders
| column | type |
|---|---|
| id | INTEGER |
| customer_id | INTEGER |
| amount | NUMERIC |
| created_at | DATE |
customers
| id | name | |
|---|---|---|
| 1 | Alice | alice@example.com |
| 2 | Bob | bob@example.com |
| 3 | Carol | carol@example.com |
orders
| id | customer_id | amount | created_at |
|---|---|---|---|
| 1 | 1 | 99.99 | 2024-01-10 |
| 2 | 3 | 49.50 | 2024-02-15 |
| 3 | 2 | 200.00 | 2024-03-01 |
| order_id | customer_name | amount | created_at |
|---|---|---|---|
| 1 | Alice | 99.99 | 2024-01-10 |
| 2 | Carol | 49.50 | 2024-02-15 |
| 3 | Bob | 200.00 | 2024-03-01 |
Order 1 belongs to customer 1 (Alice), order 2 to customer 3 (Carol), and order 3 to customer 2 (Bob). Rows are sorted by order date ascending.