Knowledge Guide
HomeDatabasesSQL Practice Problems

easy Green Product Identification

Problem Statement

Table: Inventory
Each row in this table represents a unique product, detailing its ID, whether it's organic, and whether its packaging is biodegradable.

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| product_id    | int     |
| organic       | enum    |
| biodegradable | enum    |
+---------------+---------+
product_id is the primary key for this table.
organic is an ENUM of type ('Y', 'N'), where 'Y' indicates the product is organic and 'N' indicates it is not.
biodegradable is an ENUM of type ('Y', 'N'), where 'Y' indicates the packaging is biodegradable and 'N' indicates it is not.

Develop a solution to identify the IDs of products that are both organic and have biodegradable packaging.

Example

Input:

Inventory table: +-------------+---------+--------------+ | product_id | organic | biodegradable| +-------------+---------+--------------+ | 10 | Y | N | | 11 | Y | Y | | 12 | N | Y | | 13 | Y | Y | | 14 | N | N | +-------------+---------+--------------+

Output:

+-------------+ | product_id | +-------------+ | 11 | | 13 | +-------------+

Only products with product_id 11 and 13 fulfill both these conditions, making them environmentally friendly choices in the inventory.

Try It Yourself

java
-- TODO: Write your user queries here

Solution

To solve this problem, we need to find organic products in the Inventory table with biodegradable packaging. We'll use SQL queries to filter and extract the required information.

  1. Select Product IDs: Start with a SELECT statement to query the product_id from the Inventory table.
  2. Apply Conditions: Use a WHERE clause to filter products where both organic and biodegradable fields are 'Y'.

SQL Query

Here's the final SQL query:

SELECT product_id FROM Inventory WHERE organic = 'Y' AND biodegradable = 'Y'

Step by Step Approach

Step 1: Select Product IDs

We begin by selecting the product_id from the Inventory table, which will be the basis for our output.

SELECT product_id FROM Inventory

Output After Step 1:

+-------------+ | product_id | +-------------+ | 10 | | 11 | | 12 | | 13 | | 14 | +-------------+

Step 2: Apply Conditions

Next, we refine our selection by applying conditions only to include products that are organic (organic = 'Y') and have biodegradable packaging (biodegradable = 'Y').

SELECT product_id FROM Inventory WHERE organic = 'Y' AND biodegradable = 'Y'

Final Output:

+-------------+ | product_id | +-------------+ | 11 | | 13 | +-------------+
🤖 Don't fully get this? Learn it with Claude

Stuck on Green Product Identification? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🪜 Hint ladder (no spoilers)

Progressively stronger hints — you still solve it.

I'm working on the problem **Green Product Identification** (Databases). Give me a HINT LADDER: start with the tiniest nudge, then wait. Only reveal the next, stronger hint when I ask. Do NOT show the full solution unless I type 'show solution'. Keep me doing the thinking. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🎨 Explain the approach visually

See the technique, not just code.

Explain the optimal approach to **Green Product Identification** with a VISUAL walkthrough: trace it on a small concrete example using ASCII art / a step-by-step diagram, narrate what changes each step, then give time & space complexity with a one-line derivation. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🔍 Review my solution

Catch bugs, edge cases, sub-optimality.

I'll paste my solution to **Green Product Identification**. Review it for correctness, missed edge cases, and time/space complexity, then coach me toward the optimal — don't just rewrite it. Ask me to paste my code now. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🔁 Drill the pattern

Lock in recognition with look-alikes.

Give me 2 problems that use the SAME underlying pattern as **Green Product Identification**. For each, let me attempt first, then review my answer and name the trigger signal that reveals the pattern. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes