Non-Equal Join Condition (Range Join)

#2 · 2 of 10Free sample
Question

Non-Equal Join Condition (Range Join)

Suppose you have inventory_movements and products. Imagine you only want to join inventory_movements to products where unit_price is greater than the absolute value of change_quantity. Return product_name, unit_price, change_quantity, and reason. You might need a non-equal condition in the ON clause, such as a comparison operator.
Tables
11 tables · 52 columns
customers7 cols
  • customer_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • emailTEXT
  • cityTEXT
  • join_dateTEXT
  • phoneTEXT
departments3 cols
  • department_idINTEGER
  • department_nameTEXT
  • locationTEXT
employees6 cols
  • employee_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • department_idINTEGER
  • hire_dateTEXT
  • salaryREAL
categories2 cols
  • category_idINTEGER
  • category_nameTEXT
products6 cols
  • product_idINTEGER
  • product_nameTEXT
  • category_idINTEGER
  • unit_priceREAL
  • stock_quantityINTEGER
  • creation_dateTEXT
orders6 cols
  • order_idINTEGER
  • customer_idINTEGER
  • employee_idINTEGER
  • order_dateTEXT
  • statusTEXT
  • total_amountREAL
order_items4 cols
  • order_idINTEGER
  • product_idINTEGER
  • quantityINTEGER
  • unit_priceREAL
suppliers4 cols
  • supplier_idINTEGER
  • supplier_nameTEXT
  • cityTEXT
  • products_suppliedTEXT
shipping_addresses6 cols
  • shipping_idINTEGER
  • order_idINTEGER
  • addressTEXT
  • cityTEXT
  • stateTEXT
  • postal_codeTEXT
inventory_movements5 cols
  • movement_idINTEGER
  • product_idINTEGER
  • change_quantityINTEGER
  • movement_dateTEXT
  • reasonTEXT
cities3 cols
  • city_idINTEGER
  • city_nameTEXT
  • stateTEXT
Loading the practice editor and dataset…
Your answer(autosaved)
query.sql
Loading editor…
Sign up to unlock

The reference answer is one click away.

Free account unlocks the reference answer, the explanation, and the GPT tutor on every exercise in the library.

  • Reference answer + explanation revealed after each attempt
  • GPT tutor for every problem
  • Progress saved on the platform
  • 1,598 graded exercises
  • Free forever — no credit card
All exercises in SQL: Multi-Table Joins And Complex Join Conditions