0
SELECT *
FROM banhammer_bans
INNER JOIN banhammer_players AS player
    ON banhammer_bans.player_id = player.id
INNER JOIN banhammer_players AS admin
    ON banhammer_bans.creator_id = admin.id
ORDER BY created_at DESC

banhammer_playersテーブルから3つのid列と2つの列を取得します。namePHPコードで使用できるように、これらをどのように分離できますか?

banhammer_playersには、2つの列idとが含まれていますname。banhammer_bansには2つの列(player_idおよびcreator_id)があり、どちらもbanhammer_playersテーブルと一致します。

4

2 に答える 2

1

エイリアスを使用してすべての列を明示的に選択します。

SELECT banhammer_bans.id as bans_id, banhammer_players as players_id, ...
FROM banhammer_bans
INNER JOIN banhammer_players AS player
    ON banhammer_bans.player_id = player.id
INNER JOIN banhammer_players AS admin
    ON banhammer_bans.creator_id = admin.id
ORDER BY created_at DESC
于 2012-11-11T20:41:51.450 に答える
0

クエリでエイリアスを次のように使用します。

   SELECT bans.id, player.name AS player_name, admin.name AS admin_name
   FROM banhammer_bans AS nans
   INNER JOIN banhammer_players AS player
   ON bans.player_id = player.id
   INNER JOIN banhammer_players AS admin
   ON bans.creator_id = admin.id
   ORDER BY created_at DESC;

selectあいまいな列(複数のテーブルの同じ名前の列)のテーブルエイリアスを使用して、必要な数の属性を追加できます。

于 2012-11-11T20:42:08.043 に答える