mysql - Getting Max date from multiple table after INNER JOIN -


i have 2 following tables

table 1) id |  hotel id | name  1       100      xyz  2       101      pqr 3       102      abc   table 2) id | booking id | departure date | amount 1         1       2013-04-12        100 2         1       2013-04-14        120 3         1       2013-04-9          90 4         2       2013-04-14        100 5         2       2013-04-18        150 6         3       2013-04-12        100 

i want reault in mysql such take row table 2 max departure date.

id | booking id | departure date | amount 2         1       2013-04-14        120 5         2       2013-04-18        150 6         3       2013-04-12        100 

select  b.id,         b.bookingid,         a.name,         b.departuredate,         b.amount    table1         inner join table2 b             on a.id = b.bookingid         inner join         (             select  bookingid, max(departuredate) max_date                table2             group   bookingid         ) c on  b.bookingid = c.bookingid ,                 b.departuredate = c.max_date 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -