Interview Questions/SQL/Recyclable and Low Fat Products

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 NameTypeDescription
product_idINTPrimary key
low_fatsENUM(Y, N)'Y' if product is low fat
recyclableENUM(Y, N)'Y' if product is recyclable

Example

Products

product_idlow_fatsrecyclable
0YN
1YY
2NY
3YY
4NN

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_idlow_fatsrecyclable
0YN
1YY
2NY
3YY
4NN

Output

product_id
1
3