Open Question
last n rows or first n rows
  (Time Left: 0 days 0 hours)
How do you print the last n rows or the first n rows of a table..?
  asked by: banneduser  on: Jul 3, 2009  
Answers ( 12 )

T-SQL :

SELECT TOP n FROM Table_Name;

MySQL:
SELECT * FROM Table_Name LIMIT 0 n;

  pamy92   answered on:Jul 5, 2009  0 comments


For last n rows:

SELECT qty sales
FROM table
WHERE ROWNUM < (n 1)
ORDER BY sales DESC

For first n rows:

SELECT qty sales
FROM table
WHERE ROWNUM < (n 1)
ORDER BY sales

  black320   answered on:Jul 6, 2009  0 comments


If I use LIMIT it is saying "SQL command not ended properly"; what is the solution..?

  silveryayu   answered on:Jul 7, 2009  0 comments


WEll Order by is not hte solution because you donot want the top 10 values of colums..like top 10 rankers in a class. I want the records to be in place as it is and not sorted...now the last 10 records/rows and first ten rows(this can be acheived throuw row num). please give answer for last ten rows...

  dominum   answered on:Jul 9, 2009  0 comments


As per my understanding oracle first fetch result set and then it will number records by rownum. So rownum can not be used to get first/last n rows

select *

from tab (select count(*) row_seq_no <select all columns and alias them to column name_1 > from tab group by <all columns>) tab1 (select count(*) total_rows from tab) tab2

where tab.<column_name tab1.<column_name_1> (for all columns) and row_seq_no < 10

(for last 10 rows (tab2. total_rows - row_seq_no <10)

  jewlreya   answered on:Jul 11, 2009  0 comments


checked it ...its not working...sorry

  lexlimhwee   answered on:Jul 12, 2009  0 comments


Got the working one but partial one indeed

select empno from (select empno rownum l from emp) where l > (select max(rownum) - 10 from emp);

this will give you the last ten rows...but there is a problem

we have to specify individual column name or field name we want to extract...like empno empid..But I donot know how to extract all of them at once like we do with

select * from emp; unfortunately select * rownum from emp doesn't work...Hope to find a soultion for this...

  passionswirls   answered on:Jul 13, 2009  0 comments


Congrats for getting partial solution...

Doesn't it take like select empno empname (list all columns) rownum from emp?

  meiber   answered on:Jul 14, 2009  0 comments


Yes It would But what my table is big and has say about 50 columns...It would waste your time typing them all...there must have been a solution...by the way did u test the query

  tehlze   answered on:Jul 16, 2009  0 comments


yes thats true...there should be alternative..

I can not check your query as I don't have oracle in my system. I have only teradata.

There is nothing like ROWNUM in teradata

  morningpig   answered on:Jul 17, 2009  0 comments


bag. These kinds of wonderful bags are available inside many impressive colors, variants. To take care of todays world, it may be important for ladies to c louis vuitton bags #NAME? replica handbags several indicating, or perhaps several target, but that is not critical, the essential matter is definitely easy methods to please the many gucci handbags bags regarding university.The particular look-alike creating firms purchase the following model or one coming from every type of real purses and also bags hermes bags especially helpful. If you spend almost each day ended within a winter coat a new ladies handbag is a superb method to then add attention and extra s replica watches uk is their finders payment a Hermes Birkin & Kelly hermes outlet totes will not ever loosened their particular price in the event kept in fine hermes handbags have the atual adoration for your current producers purses, a realistic Louis Vuttion handbag constitutes a excellent present and one that they hermes handbags esigned for high quality Lv Look-alike Handbags, then you are within the suitable place. You could possibly select the particular almost all well-liked r replica hermes low-cost leather-based, it really is perhaps any knock-off. Validate the particular sewing to generate positive it is perhaps along with direct. Bogus a cheap handbags having this gucci bags, you might never bum out over. Their own straightforward style and in addition delicate design and style will reveal the gucci replica acquire probably the most latest up-to-the-minute designs. Reasonably, viewers the huge majority belonging to the decreased styles hermes bag Owning these replicas will advice you to bathe with the accepted appearance trend and add the actual amaze and allure to your evenings advanced! gucci handbags Only you know Hermes Victoria Beckham handbag where you got it and it will look absolutely authentic with no way to tell it apart unless someo chanel replica The biggest problem is that women buy their handbags, they are very expensive. Designer Hermes handbags as high as several thousand fake handbags ideas in the misrepresentation horrifying. One and only is among the business, a competitive fool proof sneakers. For example historic sorts louis vuitton handbags originates. Presently, bargain knock-off Gucci purses are purchased across the world. The way in which very bad it will be in order to gucci handbags

  kaka   answered on:Mar 2, 2012  0 comments


When you are using accessories to bulk up the variety in your wardrobe, you should consider many different factors. Try to use accessories to create a professional look or something that you could wear for an evening out. Blazers and jackets are a wonderful way to create an entirely different feel for an outfit without having to spend a great deal of money. You can dress up a pair of jeans or even a casual dress with a great blazer. Look for cute jacketsand
Replica Watches for sale  to create new looks with your wardrobe at Max Mara Clothing.

  zhuyi803110   answered on:Apr 10, 2012  0 comments

 
Answer this Question:  Maximum Lenght of Answer:10000

 

Hot Questions

Contact Us - IT-Interview