是否有任何Sqlite选择查询获取两个表的结果?

时间:2013-07-26 13:13:30

标签: android sql sqlite android-layout android-emulator

我有一个名为Timings的表,其中包含以下内容

Id   Team1     Team2           MD          MT
1    Name1     Name2    26/07/2013   10.00
2    Name3     Name4    26/07/2013   11.00

另一个名为Players的表

Id     Name    Email  
Name1  Naveen  email  
Name2  Bos     email
Name3  Sharath email
Name4  mohan   email

我需要这样的结果,是否可以在单个查询中获得结果?

MD          MT      PlayerName1  playername2
26/07/2013  10.00   Naveen       Bos

1 个答案:

答案 0 :(得分:2)

尝试双倍join,如下所示

select T.MD,T.MT,P1.Name as PlayerName1, P2.Name as playername2 
from Timings T
join Players P1 on P1.Id = T.Team1
join Players P2 on P2.Id = T.Team2