从两个不同的表中查询相同的列

时间:2015-08-22 23:28:53

标签: mysql sql join inner-join

我希望每个polymer-loader的特定patch_no与... champion相同。 'Katarina'然后我想对PatchesCreated列进行排序,Patch_No列在不同的表格中,SELECT Patch_No FROM champions , info WHERE Champion = 'Katarina' ORDER BY Created DESC 在表格之间连接。

info

示例ID Patch_No Created 165 1.0.0.126 2015-08-22 21:20:03 164 1.0.0.125 2015-08-22 21:03:40 163 1.0.0.124 2015-08-22 19:28:12 162 1.0.0.123 2015-08-22 19:03:59 161 1.0.0.122 2015-08-22 18:12:19 160 1.0.0.121 2015-08-22 17:30:26 159 1.0.0.120 2015-08-21 23:19:16 158 1.0.0.119 2015-08-21 22:13:31 157 1.0.0.118 2015-08-21 21:53:44 表:

champions

示例ID Patch_No Champion 66 1.0.0.32 Ashe 67 1.0.0.32 Cho’Gath 68 1.0.0.32 1-leimerdinger 69 1.0.0.32 Karthus 70 1.0.0.32 Katarina 71 1.0.0.32 Nunu 表:

%: foo += targ

x:
    @echo $(foo)

2 个答案:

答案 0 :(得分:1)

你做得很好,只需使用INNER Join即可获得理想的结果。您可以根据您想要输出数据的方式在Order by子句中使用ASC或DESC。

SELECT C.Patch_No 
  FROM champions C
     INNER JOIN info I ON C.Patch_No  = I.Patch_No 
 WHERE Champion = 'Katarina'
 ORDER BY Created DESC

答案 1 :(得分:1)

您也可以使用此查询:

SELECT C.Patch_No 
FROM champions C, info I 
WHERE  C.Patch_No  = I.Patch_No 
AND Champion = 'Katarina'
ORDER BY Created DESC

- )