表1
Move1 Move2
Fire Ice
Grass Fire
Ice Grass
表2
Move Power
Fire 40
Grass 30
Ice 20
我有这两个表,但当我在wampserver中运行此sql语句时,不会返回任何行:
SELECT *
FROM Table1, Table2
INNER JOIN Table1 as Hello ON Hello.move1 = Table2.move
INNER JOIN Table1 as Meow ON Meow.move2 = Table2.move
两个表都在同一个数据库下,所以看不到我的错误。我希望它能像…
表1
Move1 Move2 Move Power Move Power
Fire Ice Fire 40 Ice 20
Grass Fire Grass 30 Fire 40
Ice Grass Ice 20 Grass 30
我哪里做错了?
最佳答案
这应该有效:
select
m.move1,
m.move2,
m1.move,
m1.power,
m2.move,
m2.power
from
table1 m
join table2 m1 on m1.move = m.move1
join table2 m2 on m2.move = m.move2
您可以在SQL Fiddle中进行测试。