Blog

Guides & Tutorials

Step-by-step articles on MCP servers, AI + database integrations, and more.

Why Your AI's COALESCE Counts Unset Rows as Active

Asked for active customers and the number is high. The filter is COALESCE(status, 'active') = 'active'. NULL is not active. COALESCE invented a status so the blank rows would pass.

September 29, 2026

Why Your AI's 'Daily Revenue' Is One Row Per Second

Asked for revenue by day and got hundreds of rows, each with a tiny total. GROUP BY created_at groups by the exact timestamp, not the calendar day. Two orders one second apart are two 'days.'

September 29, 2026

Why Your AI's 'Orders Today' Query Returns Nothing

Asked for orders today and got zero. created_at = CURRENT_DATE compares a timestamp to midnight. Almost no row lands on exactly 00:00:00. 'Today' is a range, not an equality.

September 29, 2026

Why Your AI's SELECT DISTINCT Made the Number Look Right — and Lied

Asked why revenue was 3× too high, the AI added DISTINCT and the total snapped to something familiar. DISTINCT collapsed join fan-out and real duplicate charges in the same pass. The number matches a dashboard. The grain is still wrong.

September 21, 2026

Why Your AI's Customer Count Includes People You Already Deleted

Asked for active customers and the number is high. The table never DELETEs — it sets deleted_at. The AI counted every row. Soft-deleted, archived, and cancelled records look like live ones until you filter them.

September 21, 2026

Why Your AI's 'Top 10 Customers' Changes Every Time You Ask

Asked for the top 10 customers and got a different ten the next day — or a different ten in the same hour. LIMIT 10 without ORDER BY is heap order, not 'best.' The query is valid. The ranking is not.

September 21, 2026

Why Your AI's 'This Month' Number Includes Last September Too

Asked for September signups and the count is huge. EXTRACT(MONTH FROM created_at) = 9 matches every September in the table — 2024, 2025, 2026. 'This month' needs a date range, not a month number.

September 17, 2026

Why Your AI's IN List Drops Rows When One Value Is NULL

Asked for orders in a set of plan IDs from a subquery and got a thin result — or nothing. IN (1, 2, NULL) is not '1 or 2 or missing.' Any NULL in an IN list makes unknown comparisons; NOT IN with a NULL can zero the whole query.

September 17, 2026

Why Your AI's Join Returned Millions of Rows

Asked for orders with customer names and got a huge result or a timeout. The JOIN has no ON, or ON 1=1, or a comma-style FROM a, b. That's a Cartesian product — every order times every customer.

September 17, 2026

Why Your AI's Join Returns the Wrong ID

Asked for orders with customer names and the id column is the customer id — or both tables' ids mashed together. SELECT * after a JOIN produces two columns named id. The model often picks the wrong one for a follow-up filter.

September 14, 2026