获取 table sql 上每个字段的名称
get the name of the of each field on a table sql
我正在尝试做一个简单的查询,但我得不到想要的结果。
我有一个 table 具有两个引用 ID 的战斗。我想要的是排成一行,每个英雄的名字基于其他 table HERO
战斗
- id
- hero1_id
- hero2_id
英雄
- id
- 姓名
我正在做这个查询
SELECT
battle.character1_id as p1,
character.name,
battle.character2_id as p2,
character.name
FROM
battle,
character
WHERE
character.id in (character1_id, character2_id)
但我通过战斗获得了两排。我知道我做错了什么,但我不知道是什么?
您需要在 hero
table 上加入 battle
两次,此处各一次:
SELECT h1.id AS id1, h1.name AS name1, h2.id AS id2, h2.name AS name2
FROM battle b
JOIN hero h1 ON h1.id = b.hero1_id
JOIN hero h2 ON h2.id = b.hero2_id
我正在尝试做一个简单的查询,但我得不到想要的结果。
我有一个 table 具有两个引用 ID 的战斗。我想要的是排成一行,每个英雄的名字基于其他 table HERO
战斗
- id
- hero1_id
- hero2_id
英雄
- id
- 姓名
我正在做这个查询
SELECT
battle.character1_id as p1,
character.name,
battle.character2_id as p2,
character.name
FROM
battle,
character
WHERE
character.id in (character1_id, character2_id)
但我通过战斗获得了两排。我知道我做错了什么,但我不知道是什么?
您需要在 hero
table 上加入 battle
两次,此处各一次:
SELECT h1.id AS id1, h1.name AS name1, h2.id AS id2, h2.name AS name2
FROM battle b
JOIN hero h1 ON h1.id = b.hero1_id
JOIN hero h2 ON h2.id = b.hero2_id