mysql - join with latest records only from another table:- Remove replication -
i have 2 table lets table1 , table2 table 1
master
data , table 2
child
. have find out records both table corresponding given table1.id
. there more 1 record in table2
corresponding table1.id
. filter latest record first table2
corresponding table1.id
apply join on filtered data table2 , table1.
table1= location_grids table2= local_ads
following doing ?
select * `location_grids`as l left join `local_ads` la on `la`.`location_grid_id` = `l`.`id` inner join (select id, location_grid_id, max(booked_till) maxbooked local_ads group location_grid_id ) b on la. location_grid_id = b.location_grid_id , la.booked_till = b.maxbooked `l`.`location_id` = '1' , `l`.`flag` = 1
the query returning me unfiltered data. how can filter apply join on data. appreciated.
table1:- location-grid table2:- local_ad
finally got solution :- searching following query.
select location_grid_id, user_id, booked_from, booked_till, purpose, category, duration, price, max( created ) local_ads group location_grid_id
here wanted run join latest record of particular id many record must exist in local_ads
Comments
Post a Comment