0

所以我有2张桌子:

包含我所有玩家的“玩家”表:

Players | stuff1| stuff2
----------------------------
1       | x1   | y1
2       | x2   | y2
3       | x3   | y3
...     | ... | ...

等等

然后我有我的“禁令”表,其中包含哪些人被禁止:

Id | Players
------------
1  | 2
2  | 5

现在,从目前“bans”的内容来看,应该说占据“玩家”表索引 2 和 5 的玩家被禁止。

我需要的是一种让我做类似'SELECT bans WHERE id = 1'的方法,它会在'players'中返回玩家2,如{2,x2,y2},我不知道我会怎么做。

帮助表示赞赏!

编辑:对不起,我的格式有点疯狂。现在应该可以阅读了!

4

4 回答 4

1

You want a join:

select playersTable.* from banTable
inner join playersTable on banTable.players = playersTable.players
where banTable.id = 1

You should really rename your players column to something else. The cells of this column don't contain players, but a player ID. I would rename it player_id.

于 2013-01-26T18:11:01.773 回答
1

如果你需要所有被禁玩家

select p.* from players p, banned b where p.Players = b.Players
于 2013-01-26T17:40:29.243 回答
0

您是否需要从 Players 中拉出玩家并显示谁被禁止?

SELECT Players.*, CASE WHEN Banned.Players IS NOT NULL THEN 'YES' ELSE NO END AS [Banned] 
FROM Players
LEFT JOIN Banned ON Players.Players = Banned.Players

这将返回所有玩家,并指示哪些玩家被禁止。

于 2013-01-26T17:40:51.323 回答
0

我认为你需要这个::

Select Players from Table where ID=? /*2 in this case*/
于 2013-01-26T17:35:37.400 回答