title: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML
body: <p>I'm getting this error:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>This is my query:</p>
  
  <pre><code>SELECT * FROM
        (SELECT H.Plotingan as 'Plotingan',
                E.EmployeeName as 'Nama',
                E.EmployeePosition as 'Jabatan',
                E.EmployeeNo as 'NIK',
                D.Tanggal,D.DutyCode
          FROM CobaDutyDetail D
          JOIN CobaDutyHeader H
            ON D.CobaDutyHeaderID = H.IDHeaderDuty
          JOIN Employee E
            ON H.EmployeeID = E.EmployeeID
         WHERE E.WorkLocation = 'JAKARTA'
         ORDER BY D.CreatedOn DESC)AS SOURCETABLE
         PIVOT(MAX(DutyCode)FOR TANGGAL IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30]))AS PIVOTTABLE
  </code></pre>