Hi, All i hope someone can help me out
so heres the situation...
i got a table lets call it 'history', and freight_bill
so my concern is, how do i get all the freight bill with its latest time stamps or information?Code:table:freight_bill ------------------------------------------------ ID | FreightBill | ------------------------------------------------ 1 | frght0001 | 2 | frght0002 | 3 | frght0003 | 4 | frght0004 | 5 | frght0005 | 6 | frght0006 | ------------------------------------------------ table: history ------------------------------------------------ ID | FreightBill | TimeStamp | status | ------------------------------------------------ 1 | frght0001 | 5pm | pending | 2 | frght0001 | 6pm | analysis | 3 | frght0001 | 7pm | analysis | 4 | frght0002 | 5pm | requeue | 5 | frght0003 | 5pm | NULL | 6 | frght0004 | 8pm | analysis | 7 | frght0004 | 8:30pm | requeue | ------------------------------------------------
so end result would be :
Code:------------------------------------------------ ID | FreightBill | TimeStamp | status | ------------------------------------------------ 1 | frght0001 | 7pm | analysis | 2 | frght0002 | 5pm | requeue | 3 | frght0003 | 5pm | null | 4 | frght0004 | 8:30pm | requeue | 5 | frght0005 | NULL | NULL | 6 | frght0006 | NULL | NULL |





Reply With Quote
,'%r') as time,substring(max(concat(a.TimeStamp,a.status)),9 ) as status FROM freight_bill as b left join history as a on b.FreightBill = a.FreightBill group by b.FreightBill;