跨表填充目标表列值时遇SQL语法错误,求排查指导
Yep, your query has two clear issues that are triggering that syntax error — let’s break them down and get it working:
1. Invalid Column Alias Syntax
The line a.Store_Picked_Up AS b.Store is the direct cause of the "." error. When using AS to rename a column, you can’t prefix the alias with a table name (like b.).
- If your goal is to pull the
Storecolumn from thePicked_Uptable (b) into your results, you don’t need the alias here at all — just referenceb.Storedirectly. - If you were trying to rename
a.Store_Picked_UptoStore, you’d writea.Store_Picked_Up AS Store(no table prefix on the alias).
Given your mention of "pulling values from another table to populate a column", I assume you want the Store column from b.
2. Missing ON Clause for INNER JOIN
Standard SQL requires an ON clause to define the join condition for INNER JOIN. While some databases let you use WHERE as a workaround, this isn’t best practice and can lead to unexpected behavior. Your join condition a.EmailAddress = b.EmailAddress belongs right after the JOIN statement, not in the WHERE clause.
Corrected Query
Here’s the fixed version that addresses both issues:
SELECT a.*, b.Store FROM [Master_List] a INNER JOIN [Picked_Up] b ON a.EmailAddress = b.EmailAddress
If you actually intended to rename a.Store_Picked_Up instead (though that doesn’t require joining b), it would look like this:
SELECT a.*, a.Store_Picked_Up AS Store FROM [Master_List] a -- Only add the JOIN if you need data from b for other columns INNER JOIN [Picked_Up] b ON a.EmailAddress = b.EmailAddress
内容的提问来源于stack exchange,提问作者JaylovesSQL

