Recyclable and Low Fat Products - Problem

You are given a Products table containing information about products and their properties.

The table has the following structure:

  • product_id: Primary key identifying each product
  • low_fats: ENUM with values 'Y' (low fat) or 'N' (not low fat)
  • recyclable: ENUM with values 'Y' (recyclable) or 'N' (not recyclable)

Write a SQL query to find the product IDs of products that are both low fat AND recyclable.

Return the result in any order.

Table Schema

Products
Column Name Type Description
product_id PK int Primary key identifying each product
low_fats enum ENUM('Y', 'N') where 'Y' means low fat, 'N' means not low fat
recyclable enum ENUM('Y', 'N') where 'Y' means recyclable, 'N' means not recyclable
Primary Key: product_id
Note: Each row represents one product with its fat content and recyclability properties

Input & Output

Example 1 — Mixed Product Properties
Input Table:
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
💡 Note:

Products 1 and 3 are both low fat (low_fats = 'Y') and recyclable (recyclable = 'Y'). Product 0 is low fat but not recyclable, product 2 is recyclable but not low fat, and product 4 is neither.

Example 2 — No Matching Products
Input Table:
product_id low_fats recyclable
5 Y N
6 N Y
7 N N
Output:
product_id
💡 Note:

No products satisfy both conditions. Product 5 is low fat but not recyclable, product 6 is recyclable but not low fat, and product 7 is neither low fat nor recyclable.

Example 3 — All Products Match
Input Table:
product_id low_fats recyclable
8 Y Y
9 Y Y
Output:
product_id
8
9
💡 Note:

Both products are low fat and recyclable, so both product IDs are returned in the result.

Constraints

  • 1 ≤ product_id ≤ 1000
  • low_fats is an ENUM of type ('Y', 'N')
  • recyclable is an ENUM of type ('Y', 'N')

Visualization

Tap to expand
Recyclable and Low Fat Products - SQL FilteringProducts Tableproduct_idlow_fatsrecyclable1YY2NY3YYWHERElow_fats = Y ANDrecyclable = YResultproduct_id13Green highlighted rows meet both criteriaRed highlighted row fails one condition
Understanding the Visualization
1
Input Table
Products with fat content and recyclability flags
2
WHERE Filter
Apply AND condition on both attributes
3
Output
Product IDs meeting both criteria
Key Takeaway
🎯 Key Insight: Use AND operator in WHERE clause to combine multiple filtering conditions efficiently
Asked in
Meta 12 Amazon 8 Google 6
125.0K Views
Very High Frequency
~5 min Avg. Time
2.9K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen