Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/10/2008, 12:13
jurena
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Cáceres
Mensajes: 3.735
Antigüedad: 16 años, 1 mes
Puntos: 300
Respuesta: LEFT JOIN con dos argumentos en el ON

SELECT T.idtrabajo, M.idmaterial, MT.cantidad, M.nombre, M.idcategoria
FROM trabajos AS T
LEFT JOIN materiales_trabajos AS MT ON(MT.idtrabajo = T.idtrabajo)
LEFT JOIN materiales AS M ON(M.idmaterial = MT.idmaterial)

ESto debería mostrártelos todos, tengan o no idcategoria 1; y cuando no tienen ninguna categoría, te mostrará null

con IFNULL podrás quitar el null y mostrar lo que quieras

SELECT T.idtrabajo, M.idmaterial, MT.cantidad, M.nombre, IFNULL(M.idcategoria,'sin categoría') id_categoria
FROM trabajos AS T
LEFT JOIN materiales_trabajos AS MT ON(MT.idtrabajo = T.idtrabajo)
LEFT JOIN materiales AS M ON(M.idmaterial = MT.idmaterial)