Welcome Back

Google icon Sign in with Google
OR
I agree to abide by Pharmadaily Terms of Service and its Privacy Policy

Create Account

Google icon Sign up with Google
OR
By signing up, you agree to our Terms of Service and Privacy Policy
Instagram
youtube
Facebook

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: