我使用了“NOT IN(select)”函数,但加载几个寄存器需要很长时间。所以我想使用LEFT JOIN改进查询,但我不知道出了什么问题。我得到了#1054 - Unknown column 'a.id_logistica' in 'on clause'
。
表“logistica”中的列“id_logistica”确实存在,就像在“det_log”表中一样。这是代码:
SELECT
a.*, a.id_logistica,
b.nombre username, c.placa,
b.nombre scliente, e.nombre ruta,
d.nombre_con, clase
FROM
logistica a, cliente b,
vehiculo c, conductores d, ruta e
LEFT OUTER JOIN
det_log t2 ON t2.id_logistica = a.id_logistica
WHERE
a.id_cliente = b.id_cliente AND a.id_ruta = e.id_ruta
AND t2.id_logistica IS NULL AND a.id_vehiculo = c.id_vehiculo
AND a.id_conductor = d.id_conductor AND activo = 1
and finalizado = 0 AND ( a.id_ruta > 1 OR a.borrado = 9 )
ORDER BY
fecha_des DESC
答案 0 :(得分:0)
如果你的查询正在运行,你可以试试这个:
SELECT
a.*, a.id_logistica,
b.nombre username, c.placa,
b.nombre scliente, e.nombre ruta,
d.nombre_con, clase
FROM logistica a
Left Join cliente b On b.id_cliente = a.id_cliente
Left Join vehiculo c On c.id_vehiculo = a.id_vehiculo
Left Join conductores d On d.id_conductor = a.id_conductor
Left Join ruta e On e.id_ruta = a.id_ruta
Left Join det_log t2 On t2.id_logistica = a.id_logistica
WHERE ( a.id_ruta > 1 OR a.borrado = 9 )
And activo = 1
And finalizado = 0
And t2.id_logistica IS NULL
ORDER BY fecha_des DESC
但是,如果我看错了。它没有意义列" id_logistica"在表格" logistica"。
请查看表格中的栏目" logistica"。
desc logistica;
也许,你写错了。