Instagram
youtube
Facebook
Twitter

Show Categories with the Lowest Priced Product Less Than 50

Show Categories with the Lowest Priced Product Less Than 50
Categories Tables:

Query Explanation:

  • "Show categories" → we select from the Categories table using alias c.

  • "With the lowest priced product < 50" → we use MIN(p.UnitPrice) to get the lowest price per category, and HAVING to filter those where the minimum price is less than 50.

  • The JOIN connects Categories with Products using CategoryID.

  • GROUP BY groups data per category so we can apply aggregate functions like MIN().

SQL Query:

SELECT 
    c.CategoryID,
    c.CategoryName,
    MIN(p.UnitPrice) AS LowestPrice
FROM 
    Categories c
JOIN 
    Products p ON c.CategoryID = p.CategoryID
GROUP BY 
    c.CategoryID, c.CategoryName
HAVING 
    MIN(p.UnitPrice) < 50;

Output: