[英]Combining multiple sql statements
I have two tables. 我有两张桌子。 Let's call them weapons
and weapon_powers
. 让我们将它们称为“ weapons
和“ weapons
weapon_powers
。
Weapons
has ID
(primary) Weapons
具有ID
(主要) weapon powers
has ID
(primary) and WEAPONTYPE
. weapon powers
WEAPONTYPE
具有ID
(主要)和WEAPONTYPE
。 WEAPONTYPE
is the ID
of the weapon the power is assigned to. WEAPONTYPE
是分配功率的武器的ID
。
A power equipped on weapon 1 would have a weapontype
of 1. 装备在武器1上的力量的武器weapontype
为1。
How do I combine these two statements into one? 如何将这两个语句合而为一?
select * from weapons where ID = somevariable
select * from weapon_powers where WEAPONTYPE = somevariable
If I'm reading your description right, it looks like you have: 如果我正确地阅读了您的描述,则看起来您已经:
WEAPONS <------->0..* WEAPON_POWERS ------- ------------- ID (PK) ? (PK) ... WEAPONTYPE (FK WEAPONS(ID)) ...
In that case I think you just want a join: 在这种情况下,我认为您只想加入:
SELECT *
FROM weapons
LEFT OUTER JOIN weapon_powers ON weapons.ID = weapon_powers.WEAPONTYPE
WHERE weapons.ID = @somevariable
This query will return all powers equipped for the given weapon, or a single row with data from weapons
and NULL
for the weapon_powers.*
columns if there are no powers equipped. 此查询将返回给定武器配备的所有力量,或者如果没有配备力量,则返回包含武器数据的单行,而weapons
weapon_powers.*
NULL
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.