我想创建一个查询,从下表中选择列 PlayerName 、 PlayerNumber 、 Location 、 PartnerName 、 PartnerNumber 、 Location :
- 玩家(列:Id、PlayerName、PlayerNumber、LocationId)
- 合作伙伴(列:Id、PartnerName、PartnerNumber、LocationId)
- 位置(列:ID、位置)
但我不知道该怎么做。有没有人有任何想法?
考虑注册表后找到更新的查询。
SELECT players.playername,
player.playernumber,
L1.location,
partners.partnername,
partners.partnernumber,
L2.location
FROM registration R
INNER JOIN players
ON players.id = R.playerid
INNER JOIN partners
ON partners.id = R.partnerid
INNER JOIN locations L1
ON players.locationid = L1.id
INNER JOIN locations L2
ON partners.locationid = L2.id
简单直接的方法
select PL.PlayerName , PL.PlayerNumber, L.Location, PT.PartnerName, PT.PartnerNumber
from Players PL, Location L, Patners PT
where L.id = PL.LocationId and L.id = P.LocationId
这也可以使用 UNION 来完成,但对此不太确定
试试这个..我不确定
select pl.Id,pl.PlayerName,pl.PlayerNumber,pa.ID,pa.PartnerName,pa.PartnerNumber,l.Location
from Players as pl,Partners as pa ,Location as l
where pl.LocationId = pa.LocationId and l.LocationId = pl.LocationId
and pa.LocationId = l.LocationId
AND l.LocationId = <some id>
select
PlayerName,
PlayerNumber,
Location,
PartnerName,
PartnerNumber
from players
left join locations
on locations.id = players.LocationId
left join partners
on partners.LocationId = locations.id
Select PlayerName , PlayerNumber, Location, PartnerName, PartnerNumber
from Players pl
inner join Partners pa on pl.LocationId=pa.LocationId
inner join Location L on L.id=pa.LocationId
where Location = 'String to search for'