sql - oracle select from 2 table restrict from 1 table and order by another -


i have book , recipient table. want select maximum 20 rows order recipient table's membershipdate column. after got it, want order book table's id column. wrote sql. there way less code?

select  *    ( select    *                ( select    b.*                            book b                                 join recipient r on r.id = b.recipient_id                           b.bookno = 115                       order  r.membershipdate desc                     )               rownum <= 20         ) order id desc 

you can remove 1 layer of select:

select * (     select    b.*          book b     join recipient r on r.id = b.recipient_id         b.bookno = 115     order  r.membershipdate desc ) rownum <= 20 order id desc; 

selecting b.* isn't good, idea, it's better specify columns want, if want them - make sure them in order expect.

you can @ row_number() analytic function in place of rownum, give more code - not should matter, effectiveness , efficiency of query rather more important length.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -