Une dos tablas a una - 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'

I'm trying to execute the following scripts. Basically, I'm showing all the rows from the table map_life, and also left joining column script de la mesa scripts y columna storage_cost de la mesa npc_data if ellos lifeid column's value match scripts's objectid and npc_data's npcid.

However, it doesn't work properly. Why's that? I can't see the correct values for storage_cost.

Muchas Gracias

preguntado el 28 de mayo de 14 a las 14:05

What database are you using, SQL Server or MySQL? More importantly, I don't see storage_cost en el capítulo respecto a la select lista. -

Can you elaborate your question please. -

1 Respuestas

Your query is missing the [storage_cost] column in the returned data set:

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

Also, it wasn't clear what table the [helper] column exists in. If the column is in the [scripts] table, then you could modify the query above by changing [helper] = 0 in the WHERE Clause to instead be script.[helper] = 0.

Adicional:

Naturally, since you are using LEFT OUTER JOINs, the returned values for script.[script] e npc.[storage_cost] puede ser NULL.

Espero que esto ayude.

contestado el 28 de mayo de 14 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.