select top 5 * from emp order by newid()

my question is , how this query get executed?

Answers were Sorted based on User's Feedback



select top 5 * from emp order by newid() my question is , how this query get executed?..

Answer / kb

Random 5 rows are selected when newid() is used.

Is This Answer Correct ?    12 Yes 0 No

select top 5 * from emp order by newid() my question is , how this query get executed?..

Answer / ankita bosamiya

first of all order by clause will be executed that is first
it will be arranged as ascending or descending order and
than first 5 records will be fatched.....

Is This Answer Correct ?    1 Yes 0 No

select top 5 * from emp order by newid() my question is , how this query get executed?..

Answer / anil sharma

newid() function return random row and top 5 return top 5
rows.
So query return top 5 row using random order.

Is This Answer Correct ?    2 Yes 1 No

select top 5 * from emp order by newid() my question is , how this query get executed?..

Answer / sanjeev kumar

newid() used with uniqueidentifier data types in a table
and uniqueidentifier datatype is used to insert randomly
new number, so the above query will give top 5 records in
randomly manner.

Is This Answer Correct ?    1 Yes 1 No

select top 5 * from emp order by newid() my question is , how this query get executed?..

Answer / praveen n h

SQL server will execute the query in following way...

Select All top 5 rows which are created in the table from
the time it is created.

reason: newid is the key given to each row regardless of
the values that goes into the row of the table.

For example.
if you have created a table temp
and inserted 10 rows, Only fives rows which are created
first will be listed.

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More SQL Server Interview Questions

what is Constraint? How many types of constraints in SQL ?

38 Answers   HCL, IBM, NIIT, Wipro,


Where are sql server usernames and passwords stored in the sql server?

0 Answers  


Ek lifafa 10 noto se bhara hai usme 2 or 5 ke note nahi hai aur usme total 50Rs hai, to batao lifafe me kon se not kitne hia it’s a challenge thank’s

6 Answers   Broadridge,


How many non clustered indexes there can be on table ?

0 Answers  


What will be the maximum number of indexes per table?

0 Answers  






is there more the two primary key in a single table?

26 Answers   Eforce, Systematix,


Can we use Truncate command on a table which is referenced by FOREIGN KEY?

2 Answers   Shriram,


What do you mean by 'normalization'?

0 Answers   Ernst Young, Thomson Reuters,


What is logshipping and its purpose?

0 Answers  


can a database be shrunk with users active? : Sql server administration

0 Answers  


Explain the properties of a relational table?

0 Answers  


Where sql server user names and passwords are stored in sql server? : sql server database administration

0 Answers  


Categories