SELECT * FROM bus_info as bus LEFT JOIN product_class as cls ON bus.class_id = cls.class_id LEFT JOIN present_condition as cnd ON bus.condition_id=cnd.condition_id LEFT JOIN route as rt ON bus.route_id=rt.route_id LEFT JOIN delivery_to as del ON bus.delivery_to_id=del.delivery_to_id LEFT JOIN depot_income as inc ON (bus.bus_id=inc.product_id AND inc.income_date = '2015-04-15') LEFT JOIN depot_exp as exp ON (bus.bus_id=exp.product_id AND exp.exp_date = '2015-04-15') LEFT JOIN repair as rpr ON (bus.bus_id=rpr.product_id AND rpr.repair_date = '2015-04-15') LEFT JOIN history_condition as his ON (bus.bus_id=his.product_id AND his.change_date = (Select max(change_date) from his.history_condition where (his.product_id = bus.bus_id and date(his.change_date) <= '2015-04-15'))) where (bus.delivery_to_id = '2' AND bus.bus_status='Active' AND bus.bus_status = 'Active') order by bus.bus_id ASC SELECT * FROM bus_info as bus LEFT JOIN product_class as cls ON bus.class_id = cls.class_id LEFT JOIN route as rt ON bus.route_id=rt.route_id LEFT JOIN delivery_to as del ON bus.delivery_to_id=del.delivery_to_id LEFT JOIN depot_income as inc ON (bus.bus_id=inc.product_id AND inc.income_date = '$idates') LEFT JOIN depot_exp as exp ON (bus.bus_id=exp.product_id AND exp.exp_date = '$idates') LEFT JOIN repair as rpr ON (bus.bus_id=rpr.product_id AND rpr.repair_date = '$idates') LEFT JOIN (SELECT product_id, his.condition_id as cond_id, cnd.condition as cond, max(change_date) as max_change_date FROM history_condition as his LEFT JOIN present_condition as cnd ON his.condition_id=cnd.condition_id WHERE date( change_date ) <= '$idates' GROUP BY product_id) as hist ON bus.bus_id=hist.product_id WHERE (bus.delivery_to_id = '".$delivery_to_id."' AND bus.bus_status='Active' AND bus.bus_status = 'Active' $bus_search) order by bus.bus_id ASC (SELECT product_id, his.condition_id as cond_id, cnd.condition as cond, max(change_date) FROM history_condition as his LEFT JOIN present_condition as cnd ON his.condition_id=cnd.condition_id WHERE date( change_date ) <= '2015-04-16' GROUP BY product_id) SELECT his.product_id, his.condition_id, cnd.condition, his.change_date FROM history_condition as his LEFT JOIN present_condition as cnd ON his.condition_id=cnd.condition_id INNER JOIN (SELECT product_id, MAX(change_date) AS change_date FROM history_condition WHERE date( change_date ) <= '2015-04-16' GROUP BY product_id) as max ON his.product_id=max.product_id AND his.change_date = max.change_date ORDER BY his.product_id SELECT * FROM history_condition WHERE change_date IN (SELECT max(change_date) FROM history_condition GROUP BY product_id) ORDER BY product_id ASC LEFT JOIN present_condition as cnd ON his.condition_id=cnd.condition_id WHERE date( change_date ) <= '2015-04-16' GROUP BY product_id JOIN (SELECT MAX(video_id) AS id FROM videos GROUP BY video_category) max ON s.video_id = max.id SELECT product_id, condition_id, max(change_date) FROM history_condition ORDER BY change_date ASC GROUP BY product_id WHERE video_id IN (SELECT DISTINCT MAX(video_id) FROM videos GROUP BY video_category) ORDER BY video_category ASC All you need is a GROUP BY clause with the MAX aggregate function: select id, max(rev) from YourTable group by id It's never that simple, is it? I just noticed you need the content column as well. This is a very common question in SQL: find the whole data for the row with some max value in a column per some group identifier. I heard that a lot during my career. Actually, it was one the questions I answered in my current job's technical interview. It is, actually, so common that StackOverflow community has created a single tag just to deal with questions like that: greatest-n-per-group. Basically, you have two approaches to solve that problem: Joining with simple group-identifier, max-value-in-group Sub-query In this approach, you first find the group-identifier, max-value-in-group (already solved above) in a sub-query. Then you join your table to the sub-query with equality on both group-identifier and max-value-in-group: select yt.id, yt.rev, yt.contents from YourTable yt inner join( select id, max(rev) rev from YourTable group by id ) ss on yt.id = ss.id and yt.rev = ss.rev Left Joining with self, tweaking join conditions and filters In this approach, you left join the table with itself. Equality, of course, goes in the group-identifier. Then, 2 smart moves: The second join condition is having left side value less than right value When you do step 1, the row(s) that actually have the max value will have NULL in the right side (it's a LEFT JOIN, remember?). Then, we filter the joined result, showing only the rows where the right side is NULL. So you end up with: select yt1.* from yourtable yt1 left outer join yourtable yt2 on (yt1.id = yt2.id and yt1.rev < yt2.rev) where yt2.id is null; Conclusion Both approaches bring the exact same result. If you have two rows with max-value-in-group for group-identifier, both rows will be in the result in both approaches. Both approaches are SQL ANSI compatible, thus, will work with your favorite RDBMS, regardless of its "flavor". Both approaches are also performance friendly, however your mileage may vary (RDBMS, DB Structure, Indexes, etc.). So when you pick one approach over the other, benchmark. And make sure you pick the one which make most of sense to you.