Jason Jason - 3 months ago 8
SQL Question

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

I am using MS Access 2010. I have inner joined two tables (2 columns from one table, and all columns from the other) and would like to use an alias on one of the columns from the table that I select all the columns. Here as an example of the current SQL

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


Right now when I run this, the vin column is returned as 'Inspections.vin'. I would like it to just read 'vin'. Is this possible?

Answer

Just add table name, currently you select all columns from both tables:

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