HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Select * on inner join with common columns

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnswithjoinselectinnercommon

Problem

I have 3 tables (mysql db) on which I want to do an inner join. The problem is that these tables have common columns. I know I could use aliases to differentiate them (select A.x as Ax, B.x as Bx, C.c as Cx ...) but this requires to list the columns. However it is not really an option. Is there a way I could give an alias to all the columns of a table at once?

Something like select a. as a?

Solution

You need to specify every column by your self.

Example : Table Country and City both have a name column

SELECT 
    a.Name AS CountryNane, b.Name AS CityName, c.*
FROM
    Country a
        JOIN
    City b ON a.Code = b.CountryCode
        JOIN
    CountryLanguage c ON a.Code = c.CountryCode;

Code Snippets

SELECT 
    a.Name AS CountryNane, b.Name AS CityName, c.*
FROM
    Country a
        JOIN
    City b ON a.Code = b.CountryCode
        JOIN
    CountryLanguage c ON a.Code = c.CountryCode;

Context

StackExchange Database Administrators Q#59336, answer score: 4

Revisions (0)

No revisions yet.