Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/03/2015, 08:54
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Consultar ultimo precio ingresado de mi tabla stock

"WHERE t2.stock IS NOT NULL" esa parte es necesaria porque se esta haciendo un left join con el subquery y este regresa varios valores con Nulls, ejecuta la consulta hasta esta parte:

Código SQL:
Ver original
  1. SELECT t1.* FROM #temp AS t1
  2. LEFT JOIN (SELECT MAX(id_stock) stock, id_producto FROM #temp GROUP BY id_producto) AS t2 ON (t1.id_producto=t2.id_producto AND t1.id_stock=t2.stock)

Y veras porque es necesario el where ;)
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me