List Low-Stock Products with Their Supplier Names
Company: Intuit
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
An inventory database stores products and the suppliers that provide them. For every product with `stock` strictly below 50, return `product_id`, `product_name`, `stock`, `price`, and the name of its supplier. Order the result by `stock` ascending, then by `product_id` ascending.
```hint Where each column lives
Four of the five output columns come from one table and the fifth from the other. Decide which table the filter applies to before you write the join.
```
### Input Table(s)
`Suppliers`
| Column | Type | Meaning |
|---|---|---|
| `supplier_id` | INT | Supplier identifier. Primary key. |
| `supplier_name` | VARCHAR(100) | Supplier's name. Not null. |
`Products`
| Column | Type | Meaning |
|---|---|---|
| `product_id` | INT | Product identifier. Primary key. |
| `product_name` | VARCHAR(100) | Product's name. Not null. |
| `supplier_id` | INT | Foreign key to `Suppliers.supplier_id`. |
| `stock` | INT | Units currently on hand. Not null, non-negative. |
| `price` | DECIMAL(10,2) | Unit price. Not null, positive. |
Keys: `Suppliers.supplier_id` and `Products.product_id` are primary keys. `Products.supplier_id` references `Suppliers.supplier_id`.
### Output Contract
- Columns, in this order: `product_id`, `product_name`, `stock`, `price`, `supplier_name`.
- One row per product with `stock < 50`.
- Sort by `stock` ascending, then `product_id` ascending. Because `product_id` is unique, the order is fully determined.
- Return `price` as stored (two decimal places). No rounding or formatting.
### Example
`Suppliers`
| supplier_id | supplier_name |
|---|---|
| 1 | Acme Parts |
| 2 | Northwind Goods |
| 3 | Blue Ridge Supply |
`Products`
| product_id | product_name | supplier_id | stock | price |
|---|---|---|---|---|
| 101 | USB Cable | 1 | 120 | 9.99 |
| 102 | Desk Lamp | 2 | 12 | 34.50 |
| 103 | Notebook | 3 | 50 | 2.25 |
| 104 | Stapler | 1 | 12 | 7.80 |
| 105 | Monitor Stand | 2 | 0 | 45.00 |
| 106 | Gel Pen Set | 3 | 49 | 4.10 |
Expected result:
| product_id | product_name | stock | price | supplier_name |
|---|---|---|---|---|
| 105 | Monitor Stand | 0 | 45.00 | Northwind Goods |
| 102 | Desk Lamp | 12 | 34.50 | Northwind Goods |
| 104 | Stapler | 12 | 7.80 | Acme Parts |
| 106 | Gel Pen Set | 49 | 4.10 | Blue Ridge Supply |
The USB Cable (120) and the Notebook (exactly 50) are left out because the threshold is strict. The Desk Lamp and the Stapler both have 12 units, so `product_id` puts 102 before 104.
### Constraints and Clarifications
- `Products` has at most 10,000 rows and `Suppliers` has at most 1,000 rows.
- Each product has exactly one supplier, and its `supplier_id` always matches a row in `Suppliers`.
- `stock`, `price`, `product_name` and `supplier_name` are never NULL.
- A product with `stock` equal to 50 does not qualify.
- Several products can share a supplier, so the same `supplier_name` can appear on more than one output row.
- If no product qualifies, return an empty result with the same columns.
Overview: Write a SQL query that lists every product with fewer than 50 units in stock together with its supplier's name, sorted by stock and then by product id. It tests an inner join on a foreign key, a strict filter threshold, and deterministic ordering with a tiebreaker column.