[英]Join two tables to one - Sql
SELECT
id, mapid, life_type, lifeid, x_pos, y_pos, foothold, min_click_pos, max_click_pos, respawn_time, life.flags, script.script
FROM
map_life life
LEFT JOIN
scripts script
ON
script.objectid = life.lifeid
AND
script.script_type = 'npc'
AND
helper = 0
LEFT JOIN
npc_data n
ON
n.npcid = life.lifeid
AND script.script_type = 'npc'
我正在尝试执行以下脚本。 基本上,我展示从表中的所有行map_life
,也留下了加盟柱script
从表scripts
和列storage_cost
从表npc_data
如果他们lifeid
列的值匹配scripts
的OBJECTID和npc_data
的npcid。
但是,它不能正常工作。 为什么? 我看不到 storage_cost 的正确值。
谢谢
您的查询在返回的数据集中缺少[storage_cost]
列:
SELECT
life.[id],
life.[mapid],
life.[life_type],
life.[lifeid],
life.[x_pos],
life.[y_pos],
life.[foothold],
life.[min_click_pos],
life.[max_click_pos],
life.[respawn_time],
life.[flags],
script.[script],
npc.[storage_cost]
FROM
[map_life] AS life
LEFT OUTER JOIN [scripts] AS script
ON ( life.[lifeid] = script.[objectid] )
LEFT OUTER JOIN [npc_data] AS npc
ON ( life.[lifeid] = npc.[npcid] )
WHERE
script.[script_type] = 'npc'
AND [helper] = 0
此外,目前还不清楚是什么表中的[helper]
中存在的列。如果列在[scripts]
表,那么你可以通过改变修改上面的查询[helper] = 0
在where子句中,而不是将script.[helper] = 0
。
添加:
当然,由于您使用的是 LEFT OUTER JOIN,因此script.[script]
和npc.[storage_cost]
的返回值可能为NULL 。
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.