exAres
exAres

Reputation: 4926

How to simply concatenate multiple tables horizontally in MySQL?

I have three tables A, B and C. All three tables contain ID1 and ID2 columns (which have exact same values in same order) and some other columns say A_x, B_x and C_x, in A, B and C respectively.

Thus A contains ID1, ID2, and A_x, and so on.

I want to simply concatenate these three tables horizontally so that resulting table will contain columns ID1, ID2, A_x, B_x and C_x. Do I really need to take a join if I know that ID1 and ID2 are exactly same in these three tables?

Upvotes: 0

Views: 415

Answers (1)

Hytool
Hytool

Reputation: 1368

    SELECT 
            a.ID1, b.ID2, a.x, b.x, c.x, < and so on >
    FROM 
            a JOIN b ON a.ID1=b.ID1 AND a.ID2=b.ID2
              JOIN c ON a.ID1=c.ID1 AND a.ID2=c.ID2

Upvotes: 1

Related Questions