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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 information regarding TOP operator

Author  Topic 

shiva.ilu2
Starting Member

2 Posts

Posted - 2010-02-22 : 00:59:32
plz can anyone explan this statement

" select TOP 2 1 from table; "

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-02-22 : 01:37:22
The TOP operator will select the specified number of records or specified percentage of the rows from a table.

Ex: Select top 5 * from location will Select First 5 records from location table.

In your example:
select TOP 2 1 from table will return 1 value two times as you are not selecting any column but a static value of 1.

Go to Top of Page

shiva.ilu2
Starting Member

2 Posts

Posted - 2010-02-22 : 02:02:02
ohh thanks a lot pk..
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-02-22 : 03:30:42
You are welcome..

Bohra
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-22 : 03:54:56
Note that TOP without Order by clause is meaningless and data will be returned in random order

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-22 : 08:44:51
quote:
Originally posted by madhivanan

Note that TOP without Order by clause is meaningless and data will be returned in random order

Madhivanan

Failing to plan is Planning to fail


In above case it doesnt matter as its just returning the same constant value two times
Generically what you say makes sense

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-22 : 09:08:30
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

Note that TOP without Order by clause is meaningless and data will be returned in random order

Madhivanan

Failing to plan is Planning to fail


In above case it doesnt matter as its just returning the same constant value two times
Generically what you say makes sense

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Yes My answer was generic

Madhivanan

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

- Advertisement -