1 / 8 · Book 15 · Your First SELECT -- Reading the Source of Truth · drill: interview Q&A⊞ allnext →Get the book →
1.3Verification Queries -- The QA Engineer's Bread and Butter
After performing an action through the UI or API, verify the result at the database level. The database is the source of truth -- if the UI says "order created" but the database has no record, the data was not actually persisted.
-- Verify user was stored correctly after API creation
SELECT id, name, email, role, created_at
FROM users
WHERE email = 'newuser@test.com';
-- Verify soft-delete worked (deleted_at should be set, not NULL)
SELECT id, email, deleted_at
FROM users
WHERE email = 'removed@test.com'
AND deleted_at IS NOT NULL;
-- Verify order total matches line items (returns rows only if inconsistent)
SELECT o.id, o.total, SUM(li.quantity * li.unit_price) AS calculated_total
FROM orders o
JOIN line_items li ON li.order_id = o.id
WHERE o.id = 42
GROUP BY o.id, o.total
HAVING o.total != SUM(li.quantity * li.unit_price);
The third query is a pattern worth memorizing: it returns rows only when there is a discrepancy. No rows returned means the data is consistent.