title: SQL Server Query Error -ORDER BY clause is invalid in views
body: <p>I am running the below code. When I run this code, I get error message: </p>
  
  <blockquote>
    <p>The ORDER BY clause is invalid in views, inline functions, derived
    tables, subqueries, and common table expressions, unless TOP or FOR
    XML is also specified.</p>
  </blockquote>
  
  <p>I'm not sure why I am getting this error message. Help is much appreciated.</p>
  
  <pre><code>SELECT  a.DELINQ_BUCKET_GROUP, a.vv_count
  FROM 
  (   
      SELECT  DELINQ_BUCKET_GROUP, 
              CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN 
                      SUM(CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN 1 ELSE 0 END)
                  ELSE COUNT(DELINQ_BUCKET_GROUP) 
              END AS vv_count 
      FROM    DCSReporting.dbo.DIM_DELINQUENT_BUCKET
      GROUP BY DELINQ_BUCKET_GROUP
      ORDER BY vv_count DESC
  ) a
  WHERE rownum&lt;=100
  </code></pre>