Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/10/2015, 12:23
ulisespalacios
 
Fecha de Ingreso: mayo-2008
Mensajes: 38
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: Mostrar resultados de 2 tablas sin repetición

Cita:
Iniciado por gnzsoloyo Ver Mensaje
Comencemos por esta prueba:
Código MySQL:
Ver original
  1. SELECT i.idIngrediente, i.nombreIngrediente, i.tipoIngrediente, IFNULL(p.cantIngrediente, 0) cantIngrediente, p.fechaPedido
  2. FROM ingredientes i LEFT JOIN pedidos p ON i.idIngrediente = p.idIngrediente
  3. WHERE TRUE OR p.idIngrediente  IS NULL;
Gnzsoloyo:

¡Muchas gracias! El query muestra los ingredientes que ya han sido "ordenados" y los que aún no, los muestra con 0. He aprovechado para hacer un ORDER BY, quedando así:
Código MySQL:
Ver original
  1. SELECT i.idIngrediente, i.nombreIngrediente, i.tipoIngrediente, i.uomIngrediente, i.ordenPideIngrediente,
  2.     IFNULL(p.cantIngrediente, 0)
  3.     cantIngrediente, p.fechaPedido
  4.     FROM ingredientes i LEFT JOIN pedidos p ON i.idIngrediente = p.idIngrediente
  5.     WHERE TRUE OR p.idIngrediente IS NULL
  6.     ORDER BY i.tipoIngrediente, i.nombreIngrediente ASC

y, para finalizar, quiero hacer que muestre las pantallas por tipoIngrediente, pero esta parte es la que aún no encuentro cómo agregar. He puesto lo siguiente pero no arroja nada diferente
Código MySQL:
Ver original
  1. SELECT i.idIngrediente, i.nombreIngrediente, i.tipoIngrediente, i.uomIngrediente, i.ordenPideIngrediente,
  2.     IFNULL(p.cantIngrediente, 0)
  3.     cantIngrediente, p.fechaPedido
  4.     FROM ingredientes i LEFT JOIN pedidos p ON i.idIngrediente = p.idIngrediente
  5.     WHERE TRUE OR p.idIngrediente IS NULL AND[B] i.tipoIngrediente = 1[/B]
  6.     ORDER BY i.tipoIngrediente, i.nombreIngrediente ASC

Si pudieras apoyarme en esta tarea, te lo agradeceré. Si no, de cualquier forma, está excelente.

Gracias de mil formas distintas!!

Saludos Cordiales
Ulises.