title: SQL ORDER BY in SQL table returning function
body: <p>so I have simple function trying to get two fields from database. I'm trying to use order by for the results however I cannot use ORDER BY in return clause.
  It tells me </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>Is is it possible to use ORDER BY in RETURN statement? I would like to avoid using order by when executing the function.</p>
  
  <pre><code>CREATE FUNCTION goalsGames1 () RETURNS TABLE
  AS RETURN(
      SELECT MAX(goals_scored) goals,
             no_games
      FROM Player
      GROUP BY no_games
      ORDER BY no_games DESC )
  </code></pre>