SQL Query to select rows based on specific condition Below is an example of childs daily activity. I want to select the next rows after the last 'Play' activity based on user id.

id          timestamp               activity
567     1541300537817000            Play
567     1541300584959000            Games
567     1541300711884001            Play
567     1541300749548000            Study
567     1541300804865000            Movie
678     1542073550481000            Computer
678     1542073551422000            Play
678     1542073551478000            Play
678     1542073561885000            Play
678     1542073567663000            Sleep     
908     1543580126943000            Tv     
908     1543580212409000            Sleep     
908     1543580245227000            Play

Expected output

id          timestamp               activity
567     1541300749548000            Study
567     1541300804865000            Movie 
678     1542073567663000            Sleep 


I tried doing this:

SELECT DISTINCT t1.*
FROM `table` t1, `table` t2
WHERE t1.id = t2.id
  AND t1.timestamp &gt; t2.timestamp
  AND t2.activity = 'Play'; 


But it is giving me events after 1st Play activity.
It is possible to solve by adding one more copy of a table for to check there is no 'Play' activity after. 

But it's better to use a subquery for to select last 'Play' activity, and get all records after it:

SELECT t1.*
FROM `table` t1, (SELECT id, MAX(`timestamp`) `timestamp`
                  FROM `table`
                  WHERE activity = 'Play'
                  GROUP BY id) t2
WHERE t1.id = t2.id
  AND t1.`timestamp` &gt; t2.`timestamp`