srowen commented on a change in pull request #27288: [SPARK-30579][DOC] 
Document ORDER BY Clause of SELECT statement in SQL Reference
URL: https://github.com/apache/spark/pull/27288#discussion_r369787855
 
 

 ##########
 File path: docs/sql-ref-syntax-qry-select-orderby.md
 ##########
 @@ -18,5 +18,121 @@ license: |
   See the License for the specific language governing permissions and
   limitations under the License.
 ---
+The <code>ORDER BY</code> clause is used to return the result rows in a sorted 
manner
+in the user specified order. Unlike the <code>SORT BY</code> clause, this 
clause guarantees
+total order in the output. 
 
-**This page is under construction**
+### Syntax
+{% highlight sql %}
+ORDER BY { expression [ sort_direction | nulls_sort_oder ] [ , ...] }
+{% endhighlight %}
+
+### Parameters
+<dl>
+  <dt><code><em>ORDER BY</em></code></dt>
+  <dd>
+    Specifies a comma-separated list of expressions along with optional 
parameters <code>sort_direction</code>
+    and <code>nulls_sort_order</code> which are used to sort the rows.
+  </dd>
+  <dt><code><em>sort_direction</em></code></dt>
+  <dd>
+    Optionally specifies whether to sort the rows in ascending (lowest to 
highest) or descending
+    (highest to lowest) order. The valid values for sort direction are 
<code>ASC</code> for ascending
+    and <code>DESC</code> for descending. If sort direction is not explicitly 
specified then by default
+    rows are sorted in ascending manner. <br><br>
+    <b>Syntax:</b>
+    <code>
+       [ ASC | DESC ]
+    </code>
+  </dd>
+  <dt><code><em>nulls_sort_order</em></code></dt>
+  <dd>
+    Optionally specifies whether NULL values are returned before/after 
non-NULL values, based on the 
+    sort direction. In Spark, NULL values are considered to be lower than any 
non-NULL values by default.
+    Therefore the ordering of NULL values depend on the sort direction.<br><br>
+    <ol>
+      <li>If the sort order is ASC, NULLS are returned first; to force NULLS 
to be last, use NULLS LAST</li>
 
 Review comment:
   Oh, my mistake, is that how it works? so NULLS FIRST puts nulls first no 
matter what the sort order? Maybe we can take the focus off of the sort order 
then.  For example NULLS LAST does the same thing no matter what the sort order.
   
   Maybe like: "NULLS FIRST forces NULLs to sort before all non-NULL values, 
regardless of the sort order" and likewise for NULLS LAST, and then explain 
that, if not specified, NULLs sort first if ASC and last if DESC. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to