开发者

How to join data from three different tables?

I have three similar tables with same fields and one field has same values. Like

Table1(Column1:USA,Column2:200)

Table2(Column1:USA,Column2:400)

Table3(Column1:USA,Column2:500)

What I want is to query data Like this:

ColumnA  Table1Value   Table2Value   Table3Value

USA        200           400           500

I know database is not normalized, but I've to use the same as ma开发者_运维技巧ny parts of the application are already using this structure


Select
  t1.Column1 AS ColumnA,
  t1.Column2 AS Table1Value,
  t2.Column2 AS Table2Value,
  t3.Column3 AS Table3Value
FROM Table1 t1
JOIN Table2 t2 ON t2.Column1 = t1.Column1
JOIN Table3 t3 ON t3.Column1 = t1.Column1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜