MySQL Select Statement - GROUP BY/Unique -


I currently use PHP / MySQL to select some data from my database My current selection statement is :

  mysql_query ("SELECT * fROM tblpm WHERE receiver_id = '$ usrID' group by thread_id ORDER by unique_id DESC) or die (mysql_error ());  

There are some columns that have "thread-id", thus, I am using the group so that only one "thread-id" column has been selected. Everything works well with the group, however, it is selecting the first 'thread-id' column, and not recently (which I want to do).

For example, there are four columns in the same thread_ID:

  thread_id unique_id 222 1 222 2 222 3 222 4  

When I'm done by the group, I want to receive it with the unique ID4 (most recently created column), not unique ID 1 (oldest column created).

How to get it with my selection statement, but any thoughts? Thank you. Select Thread_and, Max (unique_id) from tblpm GROUP to

  thread_id  

like:

  select mysql_query (& lt; & lt; & lt; END thread_id, MAX (unique_id) from WHOLE receiver_id = '$ usrID' GROUP from tblpm By thread_id END) or die (mysql_error ());  

And of course make sure that you avoid $ usrID if it comes from the browser.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -