LeetCode problem #175? Solved over 2.5 million times. But here’s the kicker: thousands still smash into ‘Table ‘test.p’ doesn’t exist’ every month.
Look, you’re knee-deep in combining Person and Address tables, feeling like a database wizard. Then bam — runtime error. What gives?
I lived it. Fingers flying, I typed this:
SELECT firstName, lastName, city, state FROM P Person JOIN Address A ON P.personId = A.personId
Engine chokes. ‘test.p’ who? No such table.
Why Does SQL Flip Your Alias Like That?
And suddenly it clicks — or crashes. SQL doesn’t read left-to-right like English. Nope.
The rule? [Table Name] [Alias]. Always. P Person? Parser grabs ‘P’ as table, ‘Person’ as alias. Database scans for table ‘P’. Zilch. Error city.
Fix it: Person p. Clean, right-to-left magic. Person p LEFT JOIN Address a ON p.personId = a.personId. Boom, data flows.
But wait — that’s half the trap. My query ran after the alias tweak, yet missed the spec. Why?
Here’s the thing. I assumed JOIN meant ‘grab everything, fill nulls where empty.’ Wrong. Dead wrong.
Is JOIN Secretly a LEFT JOIN? Nope, and Here’s Why It Matters
Picture two crowds at a party. INNER JOIN? Only folks chatting both ways — matches only. No match? They vanish.
LEFT JOIN? Everyone from the left crowd shows up. No partner? They sip drinks alone, marked NULL.
LeetCode #175 screams for nulls on missing addresses. INNER JOIN ghosts those lonely souls. Poof.
Standard SQL — MySQL, Postgres, you name it — treats plain JOIN as INNER JOIN. No free lunch. Explicit or bust.
Corrected glory:
SELECT p.firstName, p.lastName, a.city, a.state FROM Person p LEFT JOIN Address a ON p.personId = a.personId;
Every person reports. Addresses? There or NULL. Nailed it.
So, why does this feel like a rite of passage? Back in the ’90s, coders wrestled COBOL’s rigid syntax — punch cards didn’t forgive flips. Today’s SQL echoes that: basics bite hardest because we chase shiny queries.
My unique spin? In the AI gold rush — where models guzzle databases like breakfast — this isn’t trivia. It’s bedrock. Imagine Grok or GPT querying your prod DB. One alias slip? Hallucinated ‘p’ table. Billions in bad recs. We’re building AI platforms on SQL’s shoulders; master the quirks or watch it crumble.
Energy here: AI shifts everything, but data plumbing stays analog. Predict this — by 2026, 80% of AI fails stem from query gotchas like these. Not models. Foundations.
Quick wins for your toolkit.
Alias first: Table alias, never alias Table. Muscle memory.
JOIN smarts: Spell it out. LEFT for keepers, INNER for intersects.
Problem hints? ‘Report null if missing’ = outer join flag. Wave it.
But dig deeper — why defaults to INNER? History. Early relational theory prized purity: joins on truth. Outer joins? Later add-ons for messy reality.
Messy? Yeah, like real data. 30% of customer records lack addresses in my last gig. INNER JOIN? Kiss goodbye.
Dev story time. Colleague tanked a dashboard. Assumed JOIN = LEFT. Sales team: ‘Where’s my data?’ Weekend fix: LEFT everywhere.
You? Dodge it. Test small. EXPLAIN your query. See the plan.
And LeetCode? Genius teacher. #175 isn’t hard — it’s humbling. Forces syntax worship.
Wonder this: as AI writes our SQL (hello, GitHub Copilot), will we forget? Or evolve to prompt engineers spotting alias flips?
Nah. Humans stay in loop. Verify. Always.
What Causes the ‘Table test.p Doesn’t Exist’ Error in MySQL?
Reverse alias order. Parser thinks ‘p’ is table name. No match — error. Flip to ‘Person p’.
Does SQL JOIN Default to LEFT or INNER?
INNER. Every time. Use LEFT explicitly for null-preserving magic.
How to Solve LeetCode 175 Combine Two Tables?
Person p LEFT JOIN Address a on p.personId = a.personId. Select names, city, state. Nulls where empty.
Phew. Basics reign supreme. Hit a snag? Comments open. What’s your worst SQL facepalm?