Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/01/2011, 06:42
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 11 meses
Puntos: 574
Busqueda Respuesta: Consulta 3 tablas

Código MySQL:
Ver original
  1. SELECT ua.NOMBRE,
  2.        ua.APELLIDOS,
  3.        sbc.NOMBRE_FICHERO AS IMG
  4. FROM usuarios_ampliado ua
  5.        LEFT JOIN ((SELECT * FROM fotos f
  6.                        WHERE f.ID_SECCION = 4 ) sbcF
  7.                   INNER JOIN (SELECT * FROM fotos_dimensiones fd
  8.                                  WHERE fd.DIMENSIONES = '60x60') sbcFd
  9.                   ON sbcFd.ID_FOTO = sbcF.ID) sbc
  10.           ON sbc.ID_ELEMENTO = ua.ID_USUARIO
  11.   WHERE ua.ID_USUARIO = 1 LIMIT 1

1. Todos los usuarios
LEFT JOIN
2. Fotos seccion 4
INNER JOIN
3. Fotos 60x60

Con lo que tendras una lista de todos los usuarios tengan o no foto, pero solo se mostrará la fotos de los que tengan una foto que cumpla las condiciones.


esto creo que tambien...

Código MySQL:
Ver original
  1. SELECT ua.NOMBRE,
  2.        ua.APELLIDOS,
  3.        fd.NOMBRE_FICHERO AS IMG
  4. FROM ((usuarios_ampliado ua
  5.     LEFT JOIN fotos f
  6.       ON f.ID_ELEMENTO = ua.ID_USUARIO)
  7.     LEFT JOIN fotos_dimensiones fd
  8.       ON fd.ID_FOTO = f.ID )
  9.   WHERE f.ID_SECCION = 4
  10.          AND fd.DIMENSIONES = '60x60'
  11.          AND ua.ID_USUARIO = 1 LIMIT 1
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.