How to fetch last entered entry for a id from table MYSQL -


i have 3 tables:

a order goes through multiple states. each state have entry in table_orderstatus. statusdate there, not shown in example.

example

table_orders - orderid, ordervalue;

1- 500 2- 1000 3- 8000 4- 10000 

table_orderstatus - orderid, statusid, statusdate; (orderid, statusid)

1- 1  1- 2 2- 1 2- 3 3- 1  3- 3 3- 4 4- 1 4- 3 4- 4 4- 5 5- 1 

table_statusvalues - statusid, statusvalue;

1- new 2- cancel 3- confirm 4- dispatched 5- delivered 

i want fetch order_id, , last status value (not id) orders.

1- cancel 2- confirm 3- dispatched  4- delivered 5- new 

i tried multiple ways achieve same. coudn't got expected result. can me on this?

last according value:

select orderid, statusvalue (     select orderid, max(statusid) laststatus     table_orders o           inner join table_orderstatus s on s.orderid = o.orderid      group o.orderid ) l inner join table_statusvalues on statusid = laststatus 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -