Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/01/2014, 08:45
Avatar de Aoshy
Aoshy
 
Fecha de Ingreso: noviembre-2012
Ubicación: Chiclayo
Mensajes: 11
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Error en consulta Left Join

Buenas tardes

Gracias quimfv por responder a mi consulta, te comento que solucione mi dificultad hace un tiempo ya de como realizar mi consulta, para esto tube que cambiar la estructura de mi tabla o mejor dicho cambiar mi MER.... y cambiar mi consulta para que me muestre las compras y el total correspondiente ya que era lo que deseaba.

Entonces mi consulta seria esta

Código SQL:
Ver original
  1. SELECT control_venta.id_venta, control_venta.fecha, control_venta.observacion, persona.nombre, proveedor.telefono,
  2. (SELECT SUM(lineas_venta.precio) FROM lineas_venta WHERE control_venta.id_venta = lineas_venta.id_venta) AS total
  3. FROM control_venta
  4. LEFT JOIN persona ON (control_venta.id_persona = persona.id_persona)
  5. LEFT JOIN proveedor ON (control_venta.id_proveedor = proveedor.id_proveedor)
  6. WHERE control_venta.STATUS = 0
  7. ORDER BY control_venta.id_venta

Para esto modifique mi tabla lineas_venta colocanto el precio aqui y no en la tabla cuy

Código SQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `lineas_venta` (
  2.   `id_linea` INT(11) NOT NULL AUTO_INCREMENT,
  3.   `precio` DECIMAL(7,2) NOT NULL,
  4.   `id_venta` INT(11) NOT NULL,
  5.   `id_reproductor` INT(11) NOT NULL,
  6.   `id_cuy` INT(11) NOT NULL,
  7.   PRIMARY KEY (`id_linea`),
  8.   KEY `id_venta` (`id_venta`),
  9.   KEY `id_reproductor` (`id_reproductor`,`id_cuy`)
  10. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1

Código SQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `cuy` (
  2.   `id_cuy` INT(11) NOT NULL AUTO_INCREMENT,
  3.   `sexo_cuy` CHAR(1) COLLATE utf8_unicode_ci NOT NULL,
  4.   `desc_cuy` CHAR(250) COLLATE utf8_unicode_ci NOT NULL,
  5.   `flag_empadre` INT(11) NOT NULL DEFAULT '0',
  6.   `flag_parto` INT(11) NOT NULL DEFAULT '0',
  7.   `flag_estado` INT(11) NOT NULL DEFAULT '0',
  8.   `flag_condicion` INT(11) NOT NULL DEFAULT '0',
  9.   `flag_destete` INT(11) NOT NULL DEFAULT '0',
  10.   `flag_saca` INT(11) NOT NULL DEFAULT '0',
  11.   `id_jaula` INT(11) NOT NULL,
  12.   `id_subclasificacion` INT(11) NOT NULL,
  13.   PRIMARY KEY (`id_cuy`),
  14.   KEY `AI_id_cuy` (`id_cuy`),
  15.   KEY `id_jaula` (`id_jaula`),
  16.   KEY `id_subclasificacion` (`id_subclasificacion`)
  17. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1

Bueno gracias por la ayuda