Msg 1033, Level 15, State 1, Line 2The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.

Error: During executing the SQL Server Query by using Order by clause inside subquery is getting the following error:


select * from (select * from [Person].[CountryRegion] order by 1) k

Msg 1033, Level 15, State 1, Line 2
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.

Solution:

We are using order by in subquery, we can do the alternative by placing order by clause in outside query as:

select * from (select * from [Person].[CountryRegion]) k  order by 1

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.