Advertisement
L3V147H4N

INNER JOIN one to many first row

Aug 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.66 KB | None | 0 0
  1. SELECT DISTINCT
  2.        Producto.[id],
  3.        Producto.[concepto],
  4.        Producto.[costo],
  5.        Producto.[peso],
  6.        Producto.[vigente],
  7.        ProductoImagen.filename
  8. FROM [staHCR].[dbo].[Producto] AS Producto
  9.       INNER JOIN (SELECT ProductoImagen.ProductoId
  10.                          MAX(ProductoImagen.id) as id
  11.                   FROM [staHCR].[dbo].[ProductoImagen] AS ProductoImagen
  12.                   GROUP BY ProductoImagen.ProductoId)
  13.                   ProductoPrimerImagen ON ProductoPrimerImagen.ProductoId = Producto.id
  14.       INNER JOIN [staHCR].[dbo].[ProductoImagen] AS ProductoImagen
  15.             ON ProductoPrimerImagen.ID = ProductoImagen.ID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement