Oracle how to do a limit? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • How do I limit the number of rows returned by an Oracle query after ordering?

    14 answers




I have to limit to 2 rows.
But can't do it for a SQL-Fetch.



select *
from employee;









share|improve this question















marked as duplicate by Thilo, Unheilig, APC, Kaushik Nayak, Community Nov 20 at 13:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • What is the version of Oracle being used?
    – Used_By_Already
    Nov 19 at 9:04










  • Why can't you use FETCH?
    – Thilo
    Nov 19 at 10:20















up vote
0
down vote

favorite













This question already has an answer here:




  • How do I limit the number of rows returned by an Oracle query after ordering?

    14 answers




I have to limit to 2 rows.
But can't do it for a SQL-Fetch.



select *
from employee;









share|improve this question















marked as duplicate by Thilo, Unheilig, APC, Kaushik Nayak, Community Nov 20 at 13:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • What is the version of Oracle being used?
    – Used_By_Already
    Nov 19 at 9:04










  • Why can't you use FETCH?
    – Thilo
    Nov 19 at 10:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • How do I limit the number of rows returned by an Oracle query after ordering?

    14 answers




I have to limit to 2 rows.
But can't do it for a SQL-Fetch.



select *
from employee;









share|improve this question
















This question already has an answer here:




  • How do I limit the number of rows returned by an Oracle query after ordering?

    14 answers




I have to limit to 2 rows.
But can't do it for a SQL-Fetch.



select *
from employee;




This question already has an answer here:




  • How do I limit the number of rows returned by an Oracle query after ordering?

    14 answers








oracle dbi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 10:49









APC

117k15115229




117k15115229










asked Nov 19 at 9:02









Talha

62




62




marked as duplicate by Thilo, Unheilig, APC, Kaushik Nayak, Community Nov 20 at 13:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Thilo, Unheilig, APC, Kaushik Nayak, Community Nov 20 at 13:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What is the version of Oracle being used?
    – Used_By_Already
    Nov 19 at 9:04










  • Why can't you use FETCH?
    – Thilo
    Nov 19 at 10:20


















  • What is the version of Oracle being used?
    – Used_By_Already
    Nov 19 at 9:04










  • Why can't you use FETCH?
    – Thilo
    Nov 19 at 10:20
















What is the version of Oracle being used?
– Used_By_Already
Nov 19 at 9:04




What is the version of Oracle being used?
– Used_By_Already
Nov 19 at 9:04












Why can't you use FETCH?
– Thilo
Nov 19 at 10:20




Why can't you use FETCH?
– Thilo
Nov 19 at 10:20












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










You can use something like this:



 select *
from
( select *
from emp
order by data desc )
where ROWNUM <= 2;





share|improve this answer




























    up vote
    0
    down vote













    You can change the query as:



    select *
    from
    top_n_test
    order by
    num
    fetch first 3 rows only;


    The select first n rows only selects the first n rows.






    share|improve this answer























    • In the question: "But can't do it for a SQL-Fetch." ...
      – Used_By_Already
      Nov 19 at 9:12




















    up vote
    0
    down vote













    Well, the simplest way is to



    select * 
    from employee
    where rownum <= 2;


    but the question is what exactly do you want to do with that.






    share|improve this answer




























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      You can use something like this:



       select *
      from
      ( select *
      from emp
      order by data desc )
      where ROWNUM <= 2;





      share|improve this answer

























        up vote
        1
        down vote



        accepted










        You can use something like this:



         select *
        from
        ( select *
        from emp
        order by data desc )
        where ROWNUM <= 2;





        share|improve this answer























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use something like this:



           select *
          from
          ( select *
          from emp
          order by data desc )
          where ROWNUM <= 2;





          share|improve this answer












          You can use something like this:



           select *
          from
          ( select *
          from emp
          order by data desc )
          where ROWNUM <= 2;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 10:19









          Gauravsa

          1,6811816




          1,6811816
























              up vote
              0
              down vote













              You can change the query as:



              select *
              from
              top_n_test
              order by
              num
              fetch first 3 rows only;


              The select first n rows only selects the first n rows.






              share|improve this answer























              • In the question: "But can't do it for a SQL-Fetch." ...
                – Used_By_Already
                Nov 19 at 9:12

















              up vote
              0
              down vote













              You can change the query as:



              select *
              from
              top_n_test
              order by
              num
              fetch first 3 rows only;


              The select first n rows only selects the first n rows.






              share|improve this answer























              • In the question: "But can't do it for a SQL-Fetch." ...
                – Used_By_Already
                Nov 19 at 9:12















              up vote
              0
              down vote










              up vote
              0
              down vote









              You can change the query as:



              select *
              from
              top_n_test
              order by
              num
              fetch first 3 rows only;


              The select first n rows only selects the first n rows.






              share|improve this answer














              You can change the query as:



              select *
              from
              top_n_test
              order by
              num
              fetch first 3 rows only;


              The select first n rows only selects the first n rows.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 19 at 9:15









              Wernfried Domscheit

              23.5k42857




              23.5k42857










              answered Nov 19 at 9:06









              Nandan Chaturvedi

              607622




              607622












              • In the question: "But can't do it for a SQL-Fetch." ...
                – Used_By_Already
                Nov 19 at 9:12




















              • In the question: "But can't do it for a SQL-Fetch." ...
                – Used_By_Already
                Nov 19 at 9:12


















              In the question: "But can't do it for a SQL-Fetch." ...
              – Used_By_Already
              Nov 19 at 9:12






              In the question: "But can't do it for a SQL-Fetch." ...
              – Used_By_Already
              Nov 19 at 9:12












              up vote
              0
              down vote













              Well, the simplest way is to



              select * 
              from employee
              where rownum <= 2;


              but the question is what exactly do you want to do with that.






              share|improve this answer

























                up vote
                0
                down vote













                Well, the simplest way is to



                select * 
                from employee
                where rownum <= 2;


                but the question is what exactly do you want to do with that.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Well, the simplest way is to



                  select * 
                  from employee
                  where rownum <= 2;


                  but the question is what exactly do you want to do with that.






                  share|improve this answer












                  Well, the simplest way is to



                  select * 
                  from employee
                  where rownum <= 2;


                  but the question is what exactly do you want to do with that.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 10:11









                  Littlefoot

                  18.8k61333




                  18.8k61333















                      Popular posts from this blog

                      Paul Cézanne

                      UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                      Angular material date-picker (MatDatepicker) auto completes the date on focus out