views:

3966

answers:

3

I want to select the top 10 records from a table in SQL Server without arranging the table in ascending or descending order.

+3  A: 

if random order is needed, you can try

select top 10 * from [tablename] order by newid()
smoothdeveloper
creative solution +1
JohnIdol
+4  A: 

The question does not make sense. In SQL a table has no implicit ordering. They may as well be returned in random order, semantically speaking.

Limiting the results to the first 10 rows returned depends on your server's SQL dialect. In MS-SQL server, you use the TOP keyword, while in MySQL you use LIMIT, in Oracle you have to use ROWNUM, etc.

Please provide more details on what exactly you are trying to accomplish.

Tore A.
+4  A: 

SELECT TOP 10 <requiredfieldListHere> FROM <TheTableNameHere>

If you have clustered index this will return the first 10 records in the table. Note however that this would be bad form. A relational table should not be considered as having any particular order. If you don't have a clustered index, it may to return the first 10 records but could just easily return a random set.

Unless you are happy for this to return any 10 records from the table, you should apply a an ORDER BY to your query. This is true even if you have a clustered index since it may be removed or changed in the future.

AnthonyWJones