Question: How to Keep Certain Records on Top While Ordering Data?
It does not matter which version of SQL Server we are using, I think this question is going to be there universally all the time when people want to sort query using dynamic variables. Trust me, this is indeed a popular question. After 14 years of experience in the industry, just last week, I was asked this question when one of my clients was evaluating me to tune their queries. Well, for a moment I thought the client should know that I know these kind of questions. Next moment, I realize that this is my opportunity to impress them as they do know the answer.
Here is a very interesting question I received, which is based on my MySQL courses. The same script works on SQL Server as well as MySQL. Let us understand how to Order Column by Nearest Value for Any Integer.
Rick Morelan is finest SQL Expert. He is very much known for his excellent book series Joes 2 Pros. His books are not only an inspiration to many who wants to learn SQL Server properly, but a MUST read for any SQL enthusiast. He has written following guest blog post to keep alive the spirit of Interview Questions and Answers Series.
SQL SERVER – Order of Result Set of SELECT Statement on Clustered Indexed Table When ORDER BY is Not Used
“What will be the order of the result set of a SELECT statement on clustered indexed table when the ORDER BY clause is not used?”