从与另一个 table 连接的 table 内部选择 * 时如何使用列别名

how to use a column alias when selecting * from a table inner joined with another table

我正在使用 MS Access 2010。我内部连接了两个 table(一个 table 的 2 列,另一个 table 的所有列)并且想在一个上使用别名来自 table 的列,我 select 所有的列。这里以当前的SQL

为例
SELECT 
    Cars.brand, Cars.owner, * 
FROM 
    Cars INNER JOIN Inspections ON Cars.vin = Inspections.vin

现在当我 运行 这个时,vin 列返回为 'Inspections.vin'。我希望它只读 'vin'。这可能吗?

只需添加 table 名称,目前您 select 来自两个 table 的所有列:

SELECT 
    Cars.brand, Cars.owner, Inspections.* 
FROM 
    Cars INNER JOIN Inspections ON Cars.vin = Inspections.vin

您只能为 select 语句中明确包含的列分配别名。否则,查询的 all 部分内的所有内容都将 return 其原始列名

SELECT 
    Cars.brand, Cars.owner, [vin] = Cars.vin, * 
FROM 
    Cars INNER JOIN Inspections ON Cars.vin = Inspections.vin

我想这就是您要查找的内容,因为您需要 Inspections 中的所有列。如果需要别名,则不能使用 *;相反,您将需要从检查中指定您想要的每一列。在我的示例中,Inspections 似乎只有两个变量;只需添加更多 Inpections.whatever 直到您拥有所有列。

SELECT Car.brand, Cars.owner, Inspections.vin as vin, Inspections.othervar
    FROM Cars
INNER JOIN Inspections 
    ON Cars.vin = Inspections.vin