0

Hello! I need some help please..

i searched a lot, and tried everything... can someone help me please..

here's the deal:

i have this select:

SELECT * 
FROM localizacao, cliente, dispositivo                         
WHERE disp_id = clien_disp_id AND disp_id = local_disp_id 
ORDER BY local_id desc

it's output:
http://i.imagehost.org/0746/tabela.jpg

but what i really want is:

i want to select my client's, but where local_id is the last id i receive.. but i don't wanna show repetitive client's, i just want to show the last local_id for each client....
i want like to show only this ones: http://i.imagehost.org/0883/tabela2.jpg in the red circle

you know what i mean?
it's like two order by's but not showing repetitive client's... i tried distinct... but maybe im making it wrong..

help :s

thanks a lot

Edited by gpss: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by gpss
0

This was a good exercise! This code will do what you want:

select #localizacao.*, #cliente.*, #dispositivo.*
FROM #dispositivo
join #localizacao on #localizacao.local_disp_id = #dispositivo.disp_id
join #cliente on #cliente.clien_disp_id = #dispositivo.disp_id
join (
	select max(local_id) as localid, clien_id, local_disp_id
	FROM #localizacao, #cliente, #dispositivo                         
	WHERE disp_id = clien_disp_id AND disp_id = local_disp_id 
	group by local_disp_id, clien_id
) as a
on a.localid=#localizacao.local_id and a.clien_id=#cliente.clien_id and a.local_disp_id=#dispositivo.disp_id
0

Thank you so mutch spthorn!!!!!!

THANK YOU MY FRIEND, THANKS FOR YOUR HELP, IT WORKED! :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.