"Table 'test.p' doesn't exist" — Understanding SQL Aliases and Default JOIN Behavior
While solving the LeetCode #175 (Combine Two Tables) problem, I encountered a couple of unexpected errors. What seemed like a simple query taught me a valuable lesson about SQL syntax and the funda...

Source: DEV Community
While solving the LeetCode #175 (Combine Two Tables) problem, I encountered a couple of unexpected errors. What seemed like a simple query taught me a valuable lesson about SQL syntax and the fundamental behavior of JOINs. Here’s a breakdown of the "traps" I fell into and how I fixed them. 1. The Problem I initially wrote the following MySQL query to fetch person details along with their addresses: SELECT firstName, lastName, city, state FROM P Person JOIN Address A ON P.personId = A.personId However, I hit a Runtime Error: Table 'test.p' doesn't exist. Even after fixing the syntax, I realized the logic was slightly off for the problem's requirements. 2. Root Cause Analysis Error 1: Incorrect Table Aliasing In SQL, the correct order for aliasing is [Table Name] [Alias]. What I wrote: FROM P Person What happened: The SQL engine interpreted P as the table name and Person as the alias. Since there is no table named P in the database, it threw the "Table doesn't exist" error. Error 2: The