↓Skip to main content
  1. LeetCode/

LeetCode 1757: Recyclable and Low Fat Products

·1 min· ·
LeetCode Easy Database Sql
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2025-12-23

  • Submissions: Accepted (first try)

Approach
#

We want products that are low fat and recyclable, so both columns must be 'Y', joined with AND (SQL Template 1).

My Solution
#

SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y';

I originally used double quotes, "Y", which MySQL accepts by default; single quotes are the standard SQL string syntax and work across databases.

Complexity
#

One table scan, O(n).

Mistakes to Avoid
#

  • Quote strings with single quotes; in standard SQL double quotes name columns.

Interview Explanation
#

Filter with WHERE for rows where both columns are 'Y' and return product_id.

Related

LeetCode 584: Find Customer Referee
·1 min
LeetCode Easy Database Sql
LeetCode 584 note: referee_id != 2 misses NULLs, since comparing with NULL is unknown; add IS NULL explicitly
LeetCode 197: Rising Temperature
·1 min
LeetCode Easy Database
LeetCode 197 note: self-join Weather on a one-day date difference with today warmer; compare dates with DATEDIFF, never ids
LeetCode 595: Big Countries
·1 min
LeetCode Easy Database
LeetCode 595 note: filter with WHERE and OR for an area of at least 3 million or a population of at least 25 million
LeetCode 596: Classes With at Least 5 Students
·1 min
LeetCode Easy Database
LeetCode 596 note: group by class with HAVING COUNT(DISTINCT student) >= 5; older test data had duplicate rows, so count distinct students
LeetCode 620: Not Boring Movies
·1 min
LeetCode Easy Database
LeetCode 620 note: odd id and description not ‘boring’, ordered by rating from high to low
LeetCode 175: Combine Two Tables
·1 min
LeetCode Easy Database
LeetCode 175 note: people without an address must still appear, so LEFT JOIN, leaving city and state NULL when unmatched