i have 4 tables , using left join merge tables , work fine.
this query using
select cont_details.* depot_tracking left join depot_details on depot_tracking.depot_details_id = depot_details.depot_details_id left join cont_details on depot_tracking.cont_details_id = cont_details.cont_no depot_details.depot_city = "maa" , depot_tracking.status = "0" , depot_tracking.gate_out =""
and getting out !
-------------------------------------------- cont_details_id | gate_in | cont_no -------------------------------------------- 1 | 05-05-2015 | dd 1 | 13-04-2015 | cc 2 | 23-03-2015 | bb 3 | 15-05-2015 | aa 1 | 21-02-2015 | dd 3 | 25-05-2015 | cc 2 | 30-03-2015 | bb 4 | 15-05-2015 | aa
now want filter repeated rows based on depot_tracking.gate_in
column.
in image there con_details_id (1) come 2 time want 19-04-2015 (last date) maximum date , rest has filter, same 2 , 3 ,4 ,5 ,etc..,
the problem can't change gate_in column date format used change column string date formate using below query
(str_to_date(d.gate_in,'%d-%m-%y'))
so please me filter repeated rows (only show maximum date rows )
expecting output now
-------------------------------------------- cont_details_id | gate_in | cont_no -------------------------------------------- 1 | 05-05-2015 | dd 3 | 25-05-2015 | cc 2 | 30-03-2015 | bb 4 | 15-05-2015 | aa
just order table group id
select * ( select * table1 order cont_details_id asc, gate_in desc ) origin group origin.cont_details_id
replace table1
result now
sql fiddle: http://sqlfiddle.com/#!9/b90d5/1/0
Comments
Post a Comment