Question of the month January 2017 – How does ORDER BY(select statement) work?

Consider the following statement

select 'SQL Server' as db
order by (select 'a')

The result is

db
———-
SQL Server

Now the question is “What does select ‘a’ mean and how does it work in ORDER BY clause?”

Advertisements

One thought on “Question of the month January 2017 – How does ORDER BY(select statement) work?

  1. Select ‘a’ means order by Constant Expression!
    We can specify any valid expression in Order by Clause and in our case it is constant.

    It wont have any sort operation and ultimately no effects for SQL.
    we can validate same in underlying execution plan.it wont show any Sort operation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s