Conseguir un query que me devuelva esto

17/11/2008 - 10:43 por Baldor | Informe spam
Hola grupo, necesito ayuda con una SQL que no consigo hacer:

Tengo lo siguiente:

select TBLAlbaranesDetalles.id_articulo, TBLAlbaranes.fechaAlbaran,
TBLAlbaranes.nombreCliente
from TBLAlbaranesDetalles INNER JOIN TBLAlbaranes
ON TBLAlbaranesDetalles.id_albaran=TBLAlbaranes.id_albaran
where TBLAlbaranesDetalles.id_articulo IN
('0','0201095J','02050124','02050130')
order by TBLAlbaranes.fechaAlbaran DESC


Esto me podría devolver algo asi como:

0 2008-05-12 00:00:00 PEPE GOMEZ
0 2008-04-09 00:00:00 PEDRO GARCIA
0 2008-04-07 00:00:00 PEDRO GARCIA
02050130 2008-04-02 00:00:00 RAMON LOPEZ
02050130 2008-03-13 00:00:00 JOSE LUIS SANZ


Lo que necesito es que la SQL me devuelva solamente la fila más reciente, o
sea:

0 2008-05-12 00:00:00 PEPE GOMEZ
02050130 2008-04-02 00:00:00 RAMON LOPEZ


¿Alguien me puede ayudar?
 

Leer las respuestas

#1 Ricardo Junquera
17/11/2008 - 11:27 | Informe spam
Hola
Puedes intentar obtener la fecha mas reciente e incluirlo en tu select, algo
así


select TBLAlbaranesDetalles.id_articulo, TBLAlbaranes.fechaAlbaran,
TBLAlbaranes.nombreCliente
from TBLAlbaranesDetalles INNER JOIN TBLAlbaranes
ON TBLAlbaranesDetalles.id_albaran=TBLAlbaranes.id_albaran
where TBLAlbaranesDetalles.id_articulo IN
('0','0201095J','02050124','02050130')



AND TBLAlbaranes.fechaAlbaran=(SELECT MAX(fechaAlbaran) FROM TBLAlbaranes)

order by TBLAlbaranes.fechaAlbaran DESC





Ricardo Junquera
Consultor Business Intelligence

BG&S Online Consultores
Ganadora del Premio Microsoft Business Awards 2008.
Partner de Soluciones : Satisfacción de Cliente.



"Baldor" wrote:

Hola grupo, necesito ayuda con una SQL que no consigo hacer:

Tengo lo siguiente:

select TBLAlbaranesDetalles.id_articulo, TBLAlbaranes.fechaAlbaran,
TBLAlbaranes.nombreCliente
from TBLAlbaranesDetalles INNER JOIN TBLAlbaranes
ON TBLAlbaranesDetalles.id_albaran=TBLAlbaranes.id_albaran
where TBLAlbaranesDetalles.id_articulo IN
('0','0201095J','02050124','02050130')
order by TBLAlbaranes.fechaAlbaran DESC


Esto me podría devolver algo asi como:

0 2008-05-12 00:00:00 PEPE GOMEZ
0 2008-04-09 00:00:00 PEDRO GARCIA
0 2008-04-07 00:00:00 PEDRO GARCIA
02050130 2008-04-02 00:00:00 RAMON LOPEZ
02050130 2008-03-13 00:00:00 JOSE LUIS SANZ


Lo que necesito es que la SQL me devuelva solamente la fila más reciente, o
sea:

0 2008-05-12 00:00:00 PEPE GOMEZ
02050130 2008-04-02 00:00:00 RAMON LOPEZ


¿Alguien me puede ayudar?



Preguntas similares