Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help constructing MySQL Query
    text
    copied!<p>My data &amp; table is as follows:</p> <pre><code>+------+------------+-----------+--------------+------------+----------+-------------+ | sr | thread_id | thread_no | client_name | date | time | status | +------+------------+-----------+--------------+------------+----------+-------------+ | 871 | 1281473902 | 0 | Demo Company | 2011-01-17 | 16:53:00 | Closed | | 1179 | 1269343346 | 0 | Demo Company | 2010-03-23 | 11:22:00 | Open | | 1180 | 1269343585 | 0 | Demo Company | 2010-03-23 | 11:26:00 | Closed | | 1181 | 1269343679 | 0 | Demo Company | 2010-03-23 | 11:27:00 | Open | | 1182 | 1269343835 | 0 | Demo Company | 2010-03-23 | 11:30:00 | Open | | 2392 | 1295285762 | 0 | Demo Company | 2011-01-17 | 17:35:00 | Closed | | 2393 | 1295286578 | 0 | Demo Company | 2011-01-18 | 08:01:00 | Open | | 2526 | 1299764352 | 0 | Demo Company | 2011-04-29 | 11:01:00 | Closed | | 8727 | 1299764352 | 1 | Demo Company | 2011-06-16 | 09:31:00 | Closed | | 8728 | 1299764352 | 2 | Demo Company | 2011-06-16 | 09:56:00 | Closed | | 8729 | 1299764352 | 3 | Demo Company | 2011-06-16 | 09:57:00 | Closed | | 8731 | 1308234742 | 0 | Demo Company | 2011-06-16 | 10:31:00 | Open | | 8734 | 1308236479 | 0 | Demo Company | 2011-06-16 | 11:00:00 | Open-Urgent | | 8735 | 1308236519 | 0 | Demo Company | 2011-06-16 | 11:01:00 | On Hold | | 8736 | 1308236519 | 1 | Demo Company | 2011-06-16 | 11:02:00 | Closed | | 8740 | 1308242129 | 0 | Demo Company | 2011-06-16 | 12:34:00 | Closed | | 8796 | 1308242129 | 1 | Demo Company | 2011-06-24 | 06:27:00 | Closed | | 8798 | 1308242129 | 2 | Demo Company | 2011-06-24 | 07:43:00 | Open | | 8799 | 1308242129 | 3 | Demo Company | 2011-06-24 | 07:44:00 | Open | +------+------------+-----------+--------------+------------+----------+-------------+ </code></pre> <p>I need to select ROWS with DISTINCT thread_id and having the highest value of thread_no for that distinct thread_id</p> <p>For example, for thread_id 1299764352, I need to select the row with sr=8729</p> <p>The closes I could come to was with this query:</p> <pre><code>SELECT sr, thread_id, max(thread_no) as thread_no, client_name, date, time, status FROM table group by thread_id order by sr </code></pre> <p>But this query gives me the row with thread_no=0 and not the row with highest value of thread_no</p> <p>I hope I was able to explain well.</p> <p>Please help.</p> <p>Thx Vai</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload