944,027 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 534
  • MySQL RSS
Oct 21st, 2009
0

help - ordering

Expand Post »
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:

MySQL Syntax (Toggle Plain Text)
  1. SELECT *
  2. FROM localizacao, cliente, dispositivo
  3. WHERE disp_id = clien_disp_id AND disp_id = local_disp_id
  4. 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
Last edited by gpss; Oct 21st, 2009 at 12:53 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gpss is offline Offline
24 posts
since Oct 2009
Oct 22nd, 2009
0
Re: help - ordering
This was a good exercise! This code will do what you want:
MySQL Syntax (Toggle Plain Text)
  1. SELECT #localizacao.*, #cliente.*, #dispositivo.*
  2. FROM #dispositivo
  3. JOIN #localizacao on #localizacao.local_disp_id = #dispositivo.disp_id
  4. JOIN #cliente on #cliente.clien_disp_id = #dispositivo.disp_id
  5. JOIN (
  6. SELECT max(local_id) as localid, clien_id, local_disp_id
  7. FROM #localizacao, #cliente, #dispositivo
  8. WHERE disp_id = clien_disp_id AND disp_id = local_disp_id
  9. GROUP BY local_disp_id, clien_id
  10. ) as a
  11. on a.localid=#localizacao.local_id and a.clien_id=#cliente.clien_id and a.local_disp_id=#dispositivo.disp_id
Reputation Points: 10
Solved Threads: 5
Newbie Poster
spthorn is offline Offline
21 posts
since Sep 2007
Oct 22nd, 2009
0
Re: help - ordering
Thank you so mutch spthorn!!!!!!

THANK YOU MY FRIEND, THANKS FOR YOUR HELP, IT WORKED!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gpss is offline Offline
24 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: SQL Server 2005 error
Next Thread in MySQL Forum Timeline: Inserting data to mysql database using php created form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC