Easy
Database
Updated Sep 2026

Recyclable and Low Fat Products

Asked at Google

Problem

Write a SQL query to find the ids of products that are both recyclable and low fat. The Products table contains product_id, name, recyclable, and low_fat columns. This tests basic SQL filtering with multiple conditions.

Asked At

CompanyDifficulty
GoogleEasyView all Google questions →

How to Think About It

1.

Simple WHERE clause: filter on two boolean conditions. WHERE recyclable = "Y" AND low_fat = "Y". This is a straightforward O(n) scan of the Products table.

2.

Visual walkthrough for table: id=1 name=Apple recyclable=Y low_fat=N, id=2 name=Banana recyclable=N low_fat=Y, id=3 name=Orange recyclable=Y low_fat=Y.
id=1: recyclable=Y but low_fat=N -> excluded
id=2: recyclable=N but low_fat=Y -> excluded
id=3: recyclable=Y and low_fat=Y -> included. Result: [3].

3.

Column types: recyclable and low_fat are varchar with values "Y" or "N", not boolean. Compare with string literals, not 1/0 or true/false.

4.

The query is just SELECT product_id FROM Products WHERE recyclable = "Y" AND low_fat = "Y". No joins, no aggregation, no subqueries. Pure filtering.

5.

Edge cases: all products could be recyclable and low fat (return all ids), none could be (return empty), or the table could be empty (return empty). All handled by the same query.

Optimal Approach

Step 1: SELECT product_id from the Products table.
Step 2: WHERE clause filters recyclable = "Y" AND low_fat = "Y".
Step 3: Return all matching product_ids.

Walkthrough: For [[1, Apple, Y, N], [2, Banana, N, Y], [3, Orange, Y, Y]]:

  • Product 1: recyclable=Y, low_fat=N -> fails
  • Product 2: recyclable=N, low_fat=Y -> fails
  • Product 3: recyclable=Y, low_fat=Y -> passes
  • Result: [3]

Time: O(n) for a full table scan. Space: O(1) for the query execution.

What Trips People Up in Real Interviews

1.

Comparing with boolean values instead of strings. recyclable = true won't work if the column stores "Y"/"N" as varchar. Check the schema carefully before writing the query.

2.

Using OR instead of AND. The problem asks for products that are BOTH recyclable AND low fat. OR would return products that are recyclable OR low fat, which is a much larger set.

3.

Selecting product name instead of product_id. The problem asks for ids, not names. SELECT product_id is correct.

4.

Adding unnecessary DISTINCT. Each product_id is already unique as a primary key. DISTINCT is harmless but wasteful and shows you're not confident about the schema.

5.

Forgetting that the table might have no matching rows. The query returns an empty result set, which is valid. Don't add a UNION with a fake row or anything creative.

Solution Code

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

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Recyclable and Low Fat Products problem?

Write a SQL query to find the ids of products that are both recyclable and low fat. The Products table contains product_id, name, recyclable, and low_fat columns. This tests basic SQL filtering with multiple conditions.

How do you solve Recyclable and Low Fat Products?

The optimal approach is described in detail above, including step-by-step walkthroughs, complexity analysis, and solution code in Python. Scroll up to the "Optimal Approach" section.

What companies ask Recyclable and Low Fat Products?

Recyclable and Low Fat Products is asked at Google. It is a easy difficulty problem.

What are common mistakes on Recyclable and Low Fat Products?
  • Comparing with boolean values instead of strings. `recyclable = true` won't work if the column stores "Y"/"N" as varchar. Check the schema carefully before writing the query.
  • Using OR instead of AND. The problem asks for products that are BOTH recyclable AND low fat. `OR` would return products that are recyclable OR low fat, which is a much larger set.
  • Selecting product name instead of product_id. The problem asks for ids, not names. `SELECT product_id` is correct.
  • Adding unnecessary DISTINCT. Each product_id is already unique as a primary key. DISTINCT is harmless but wasteful and shows you're not confident about the schema.
  • Forgetting that the table might have no matching rows. The query returns an empty result set, which is valid. Don't add a UNION with a fake row or anything creative.