Find rows violating a constraint rule
SQL
Hard
5 views
Problem Description
In Products(product_id, price), price should be > 0 but table has old bad data. Write a query to find all invalid rows before adding a CHECK constraint.
Sample Test Case
Input:
Products(product_id, price)
Output:
List of invalid products
Official Solution
SELECT product_id, price FROM Products WHERE price IS NULL OR price <= 0;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!