Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query to get top 100 rows from the table x

Author  Topic 

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-05-06 : 03:24:43
what is query to get top 100 rows from the table x

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-06 : 03:35:23
SELECT Top 100 field1,field2,.. from x order by orderfield
Where orderfield is field based on which you want top 100 rows
Go to Top of Page

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-05-06 : 03:37:04
give me with example
Go to Top of Page

Anoop
Starting Member

6 Posts

Posted - 2008-05-06 : 03:57:39

CREATE TABLE tbl1 (col1 int)

INSERT INTO tbl1 VALUES (1)
INSERT INTO tbl1 VALUES (2)
INSERT INTO tbl1 VALUES (3)
INSERT INTO tbl1 VALUES (4)
INSERT INTO tbl1 VALUES (5)
INSERT INTO tbl1 VALUES (6)

SELECT TOP 3 *
FROM tbl1
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-08 : 06:44:27
quote:
Originally posted by Anoop


CREATE TABLE tbl1 (col1 int)

INSERT INTO tbl1 VALUES (1)
INSERT INTO tbl1 VALUES (2)
INSERT INTO tbl1 VALUES (3)
INSERT INTO tbl1 VALUES (4)
INSERT INTO tbl1 VALUES (5)
INSERT INTO tbl1 VALUES (6)

SELECT TOP 3 *
FROM tbl1


You should use ORDER BY Clause

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eralper
Yak Posting Veteran

66 Posts

Posted - 2008-05-08 : 06:53:58

SELECT TOP 100 * from tbl1 order by col1




-------------
Eralper
http://www.kodyaz.com
Go to Top of Page
   

- Advertisement -