sql server - SQL | Criteria Query for max value in a subquery -


i need find out row corresponding row in table2 gives single row output below query. writing jpa criteria query query. able max(date) subquery not exact row (corresponding max value) table2.

select table2.er col_0_0_,        table1.cr col_1_0_ table1 table1 cross join table2 table2 table2.date=     (select max(table2i.date)      table3 table3 cross      join table2 table2i      table2i.id=table2.id        , table2i.fc=?        , table2i.tc=?        , table2i.tcob=?        , table2i.fcob=?        , table2i.tc=table1.id        , table2i.rt=?        , table2i.rtob=?        , table3.id=?        , table2i.date<=table3.cd) 

to limit join single row, instead of joining on date, join on id:

where table2.id=(   select top 1 table2i.id   table2 table2i   cross join table3    ...   order date desc ) 

the order date desc forces choose row has highest date value, limits 1 row (top 1).


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -