I have the following query:
SELECT AR.ARTICULO,AR.DESCRIPCION,AP.PRECIO,
(SELECT AF.FOTO FROM EXSD.ARTICULO_FOTO AF WHERE AF.SECUENCIA = 1 AND AF.ARTICULO = AR.ARTICULO) AS 'FOTO'
FROM EXSD.ARTICULO AR JOIN EXSD.ARTICULO_PRECIO AP ON AR.ARTICULO = AP.ARTICULO
JOIN EXSD.VERSION_NIVEL VN ON AP.NIVEL_PRECIO = VN.NIVEL_PRECIO
AND AP.VERSION = VN.VERSION AND VN.MONEDA = AP.MONEDA
WHERE AP.NIVEL_PRECIO = 'ND-LOCAL' AND
AP.VERSION = '11' AND AP.MONEDA = 'L' AND VN.SINC_MOVIL = 'S'
Which returns the following result:
And I'm trying to perform that same query but without the subquery :
SELECT AR.ARTICULO,AR.DESCRIPCION,AP.PRECIO,ARTICULO_FOTO.FOTO
FROM EXSD.ARTICULO AR JOIN EXSD.ARTICULO_PRECIO AP ON AR.ARTICULO = AP.ARTICULO
JOIN EXSD.VERSION_NIVEL VN ON AP.NIVEL_PRECIO = VN.NIVEL_PRECIO
AND AP.VERSION = VN.VERSION AND VN.MONEDA = AP.MONEDA
join EXSD.ARTICULO_FOTO on
ARTICULO_FOTO.SECUENCIA = 1
AND ARTICULO_FOTO.ARTICULO = AR.ARTICULO
WHERE AP.NIVEL_PRECIO = 'ND-LOCAL' AND
AP.VERSION = '11' AND AP.MONEDA = 'L' AND VN.SINC_MOVIL = 'S'
however I am not getting the same result :
How can I get the same result of the first query in the second without having to use the subquery?????????
I solved it with a Left Join: