Subquery returns more than 1 row - Mysql with Visual Studio 2010 -


i have next code in mysql:

("select id_viaje,         (select nombre            unidades,                 viaje           id_unidad = id_unidades),         (select nombre            empleados,                 viaje           id_empleado = id_conductor),         (select nombre            empleados,                 viaje           id_empleado = id_guarda),         (select nombre            ciudad,                 viaje           id_ciudad = id_salida),         (select nombre            ciudad,                 viaje           id_ciudad = id_llegada),         fecha_salida,         fecha_llegada    viaje; ") 

i have tried limit 1 @ end of each one, have replaced = in , have no idea why showing me error:

22:30:30    select id_viaje, (select nombre unidades, viaje id_unidad in (id_unidades)) , (select nombre empleados, viaje id_empleado in (id_conductor)) ,(select nombre empleados, viaje id_empleado in (id_guarda)) , (select nombre ciudad, viaje id_ciudad in (id_salida)) , (select nombre ciudad, viaje id_ciudad in (id_llegada)) , fecha_salida, fecha_llegada viaje limit 1      error code: 1242 subquery returns more 1 row 

please need quickly!

this error returned when subquery returns multiple rows when supposed return single row.

your subquery logic wrong. when put subquery inside select statement, must sure subquery return 0 or 1 row.

what can putting left join , use few aliases in query, this:

select id_viaje,         u.nombre unidade_nombre,        e_con.nombre conductor_nombre,         e_grd.nombre guarda_nombre,         c_salida.nombre salida_nombre,        c_llegada.nombre llegada_nombre,         fecha_salida,         fecha_llegada    viaje v left join unidades u on v.id_unidad = u.id_unidades left join empleados e_con on e.id_empleado = v.id_conductor left join empleados e_grd on e.id_empleado = v.id_guarda left join ciudad c_salida on e.id_salida = c_salida.id_ciudad left join ciudad c_llegada on e.id_llegada = c_llegada.id_ciudad ; 

try running in mysql workbench first , if runs successfylly there should put application code.

also note code not supposed run in first attempt. please make applicable corrections before running code.

read more mysql joins , mysql subqery


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -