title: SQL Error "The ORDER BY clause is invalid in views..."
body: <p>I have a SQL Server error I'm trying to resolve. Could someone please help me out?</p>
  <p>The query is:</p>
  <pre><code>SELECT TOP 10 * 
  FROM ( 
  SELECT c.id, c.name, c.inserteddate, c.cityname, ftblstates.name AS statename, clc.name AS catname, '' AS listingimagelogo, '' AS orgname, relocateyn, '' AS employerclassified
  FROM ((tblclassifieds c 
  LEFT JOIN tblclassifiedscategories clc ON c.categoryid = clc.id) 
  LEFT JOIN ftblstates ON c.stateid = ftblstates.id) 
  WHERE (c.expirydate != '') AND NOT c.id IN ( 
  SELECT TOP 10 tblclassifieds.id 
  FROM tblclassifieds 
  WHERE (c.expirydate != '') 
  ORDER BY inserteddate desc) 
  UNION ALL 
  SELECT ce.id, ce.name, ce.inserteddate, suburb AS cityname, ftblstates.name AS statename, ce.jobtype AS catname, ce.listingimagelogo, ce.orgname, '' AS relocateyn, '1' AS employerclassified 
  FROM tblclassifiedemployers ce 
  LEFT JOIN ftblstates ON ce.stateid = ftblstates.id 
  WHERE (ce.expirydate != '') AND NOT ce.id IN ( 
  SELECT TOP 10 tblclassifiedemployers.id 
  FROM tblclassifiedemployers 
  WHERE (ce.expirydate != '') 
  ORDER BY inserteddate desc) 
  ORDER BY inserteddate desc; 
  </code></pre>
  <p>And the error:</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>