AI Hints
Homeโ€บSQL Tutorialโ€บReading Error Messages
SQL ยท Lesson 107 of 126

Silent Mistakes

No error, wrong answer.

โฑ 2 min readโ–ถ Video at 2:31:14๐ŸŽ“ Free
Watch this lesson in the SQL courseWatch on YouTube โ†—Full SQL course

Errors are actually the friendly mistakes. They stop you, and tell you what's wrong. The dangerous mistakes are the silent ones. The query runs, and gives you an answer. It's just the wrong answer.

Silent Mistakes
From the video: Silent Mistakes
  • Errors are friendly
  • Silent mistakes are dangerous
  • Runs fine, wrong answer

The missing comma

Can you spot the problem? There's no comma between title and price. Run it. No error. But we only got one column, and it's called price. Without the comma, SQL thought price was an alias for title.

query.sqlsql
SELECT title price
FROM books
LIMIT 3;
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       price        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ The Silent Orchard โ”‚
โ”‚ Code of the River  โ”‚
โ”‚ Stars Over Lagos   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The wrong case

We're looking for fantasy books, but typed fantasy with a small f. Run it. Nothing. No error, just an empty result. Text comparisons are case sensitive, and the genre is stored as fantasy with a capital F.

query.sqlsql
SELECT title
FROM books
WHERE genre = 'fantasy';

The fix

One safe fix is to lower both sides. Then it doesn't matter how the data was typed. Run it. Three fantasy books.

query.sqlsql
SELECT title
FROM books
WHERE LOWER(genre) = 'fantasy';
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        title         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dragons of Ember Bay โ”‚
โ”‚ Crown of Ash         โ”‚
โ”‚ The Glass Forest     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

How to catch silent mistakes

So how do you catch mistakes that don't announce themselves? Look at the column names in the result. Check row counts against what you expect. Test with a value you know. And if a result is empty, or seems too good, be suspicious.

Column namesare they right?
Row countsas expected?
Known valuestest with one
Empty or perfect?be suspicious

Summary

Silent mistakes don't stop you, so you have to catch them yourself. Check names, counts, and known values. Next, turning rows into a neat summary table.

Key takeaways
  • Missing comma = alias
  • Text is case sensitive
  • Check every result
Next up: Pivot Tables in SQL โ€” rows into columns