Example 1
Find inventory rows with invalid negative values
The intended rule is that quantity and price cannot be negative. Row 2 violates the quantity rule, and row 3 violates the price rule. Rows 1 and 4 already satisfy both checks, so they are not returned.
CREATE TABLE inventory (id INT, item VARCHAR(50), quantity INT, price INT);
INSERT INTO
inventory
VALUES
(1, 'Widget', 12, 25),
(2, 'Gadget', -3, 10),
(3, 'Cable', 5, -1),
(4, 'Bracket', 0, 8);SELECT
id,
item,
quantity,
price
FROM
inventory
WHERE
quantity < 0
OR price < 0
ORDER BY
id;| id | item | quantity | price |
|---|---|---|---|
| 2 | Gadget | -3 | 10 |
| 3 | Cable | 5 | -1 |
The rule is a simple predicate, so the same audit SQL and result work across supported engines.