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

1 01 101 01010

0 Answers  


What is mean by "fill factor" ? and what is mean by "Index "in sql?

1 Answers   iGate, Logica CMG,


What are the built in functions in sql server?

0 Answers  


How do you trace the traffic hitting a sql server?

0 Answers  


What are the events recorded in a transaction log?

0 Answers  






What is cross join in sql server joins?

0 Answers  


Explain different forms of normalization?

0 Answers  


What are statistics, under what circumstances they go out of date, how do you update them?

2 Answers   HCL,


i want to join two queries....and i want to run them as one after another that is want output of first query then second , then again output of first query then second and so on...

2 Answers  


Write an sql query to sort a table according to the amounts in a row and find the second largest amount.

0 Answers   Amazon,


When we are using this query to shrink the log file,what exactly it will execute internally? Do we lose any data when we run this script? which data it will truncate in the log file and where it is saved. Please let me know... USE DatabaseName GO DBCC SHRINKFILE(<TransactionLogName>, 1) BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY DBCC SHRINKFILE(<TransactionLogName>, 1) GO

1 Answers   Cognizant,


What is data source object?

0 Answers  


Categories