954,113 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help - ordering

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

gpss
Newbie Poster
24 posts since Oct 2009
Reputation Points: 10
Solved Threads: 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
spthorn
Newbie Poster
21 posts since Sep 2007
Reputation Points: 10
Solved Threads: 5
 

Thank you so mutch spthorn!!!!!!

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

gpss
Newbie Poster
24 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You