The purpose of this SQL query would be to extract the record 10192 only, because the end_time is both in the past and its foreign counterpart in the Node table still has the status 1. I don't want to select the record 10111 because it hasn't expired.I've just finished writing this SQL query, it works! Although I'm sure it can be written better and I'm interested to here what you have to say.SELECT MAX(l.id) AS highestID, l.nid, n.status                        FROM mbl AS l                        INNER JOIN node AS n                        ON l.nid = n.nid                        WHERE n.status = 1                        AND (   SELECT end_time                                 FROM mbl                                WHERE id = (    SELECT MAX(id)                                                 FROM mbl                                                WHERE nid = l.nid                                                GROUP BY nid                                            )                            ) <= NOW()                        GROUP BY l.nidMlb table data:id  | nid | start_time | end_time105 | 5 | 20/07/2014 01:00:00 | 24/07/2014 01:00:00589 | 52 | 20/07/2014 01:00:00 | 31/07/2015 01:32:0010108 | 874 | 20/07/2014 01:00:00 | 24/07/2014 01:00:0010111 | 874 | 20/07/2014 01:00:00 | 24/07/2015 01:00:00 10156 | 967 | 20/07/2012 01:00:00 | 24/07/2013 01:00:0010161 | 967 | 20/07/2013 01:00:00 | 20/07/2014 01:00:0010192 | 967 | 20/07/2014 01:00:00 | 24/07/2014 01:00:00Node table data:nid  | status5 | 052 | 1874 | 1967 | 1
Extracting certain records
sql;mysql