Bird
0
0

Given tables Products(product_id, price) and Discounts(min_price, max_price, discount_rate), what does this query return?

medium📝 query result Q13 of 15
SQL - Advanced Joins
Given tables Products(product_id, price) and Discounts(min_price, max_price, discount_rate), what does this query return?
SELECT p.product_id, d.discount_rate
FROM Products p
JOIN Discounts d ON p.price >= d.min_price AND p.price < d.max_price;
AOnly products with price exactly equal to min_price or max_price.
BAll products joined with all discounts regardless of price.
CAll products with their matching discount rate based on price ranges.
DSyntax error due to invalid join condition.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze join condition

    The join matches products where price is between min_price (inclusive) and max_price (exclusive).
  2. Step 2: Understand result

    This returns products with their discount rate if their price falls in the discount's price range.
  3. Final Answer:

    All products with their matching discount rate based on price ranges. -> Option C
  4. Quick Check:

    Non-equi join matches price ranges = All products with their matching discount rate based on price ranges. [OK]
Quick Trick: Non-equi join matches ranges using >= and < [OK]
Common Mistakes:
MISTAKES
  • Thinking only exact matches are returned
  • Assuming all products join with all discounts
  • Believing the query has syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes