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

Leave a Comment

Your email address will not be published.