Recyclable and Low Fat Products
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Description
You have a Products table. Each product has two flags: low_fats and recyclable, each either 'Y' (yes) or 'N' (no). Write a SQL query to find the IDs of products that are both low fat AND recyclable. Return the result in any order.
Database Schema
Products
| Column Name | Type | Description |
|---|---|---|
| product_id | INT | Primary key |
| low_fats | ENUM(Y, N) | 'Y' if product is low fat |
| recyclable | ENUM(Y, N) | 'Y' if product is recyclable |
Example
Products
| product_id | low_fats | recyclable |
|---|---|---|
| 0 | Y | N |
| 1 | Y | Y |
| 2 | N | Y |
| 3 | Y | Y |
| 4 | N | N |
Output
| product_id |
|---|
| 1 |
| 3 |
Explanation:
Only products 1 and 3 have both low_fats='Y' and recyclable='Y'.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
SQL Editor
Loading...
Products
| product_id | low_fats | recyclable |
|---|---|---|
| 0 | Y | N |
| 1 | Y | Y |
| 2 | N | Y |
| 3 | Y | Y |
| 4 | N | N |
Output
| product_id |
|---|
| 1 |
| 3 |