Select the latest line that matches the conditions in SQLITE

Suppose I have a table:

Name, status, timestamp

I want to choose matching Status =’active’ rows, but only those rows with the latest timestamp are selected. So if there are rows like this:

Bob, active, 5/10/2010< br />Bob, active, 6/12/2010
Ann, inactive, 6/12/2000
Ann, active, 9/3/2009
Ann, active, 9/25/ 2010

I want it to return:

Bob, active, 6/12/2010
Ann, active, 9/25/2010< /pre>

How can I do this? I am using SQLite, if it matters.

Thank you.

select name, status, max(timestamp) 
from my_table
where status ='active'
group by name, status

Look at http://www. w3schools.com/sql/sql_groupby.asp

Suppose I have a table:

Name, status , timestamp

I want to select rows that match status='active', but only those with the latest timestamp. So if there are rows like this:

Bob, active, 5/10/2010
Bob, active, 6/12/2010
Ann, inactive, 6/12/2000
Ann, active, 9/3/ 2009
Ann, active, 9/25/2010

I want it to return:

Bob, active, 6/12/2010< br />Ann, active, 9/25/2010

How can I do this? I am using SQLite, if it matters.

Thank you.

select name, status, max(timestamp) 
from my_table
where status ='active'
group by name, status

Look at http://www.w3schools.com/sql/sql_groupby.asp

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 953 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.