AnalystPracticeGuides
DashboardSign up

How to check SQL written by AI

AI writes SQL that runs on the first try and still returns the wrong number. The query doesn't fail, the logic does. Check the row counts and a few results by hand before you trust it.

What does AI typically get wrong?

MistakeHow to spot it
Join on a non-unique keythe row count jumps after the join
Filter on the right table after LEFT JOINrows without a match disappear
NULL handling= NULL, NOT IN with NULLs, AVG ignoring NULLs
Date rangesBETWEEN missing the last day, wrong time zone
Wrong dialectTOP vs LIMIT, date functions from another database
Invented columnsa column name that isn't in your schema
COUNT(*) vs COUNT(DISTINCT)customers counted per order

How do you test an AI query?

Count rows at each step: the base table, after each join, after WHERE. If the number changes where it shouldn't, that step is wrong. Then pick two or three IDs and calculate their result by hand.

How do you ask for better SQL?

Paste the table schema (CREATE TABLE statements) and say which database you use. Ask for the query and a short explanation of each join and filter. Read the explanation; it often reveals a wrong assumption.

Why this matters in interviews

Interviewers now show a query and ask "what's wrong with it?" Finding the bug in AI SQL is becoming a standard data analyst task.

Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise checking AI SQL Practise checking AI summaries

Updated November 2026.

← All free guides