Friday, September 18, 2009

Sorting retrieved rows in postgresql

Using the ORDER BY Clause :
  • Sort retrieved rows with the ORDER BY clause
    • ASC: ascending order, default
    • DESC: descending order
  • The ORDER BY clause comes last in the SELECT statement
  • SELECT ename, job, deptno, hiredate FROM emp ORDER BY hiredate ;
Sorting in descending order :
  • SELECT ename, job, deptno, hiredate FROM emp ORDER BY hiredate DESC ;

Rules of Precedence in SQL



Rules of Precedence :
  1. Arithmetic operators
  2. Concatenation operator
  3. Comparison conditions
  4. IS [NOT] NULL, LIKE, [NOT] IN
  5. [NOT] BETWEEN
  6. Not equal to
  7. NOT logical condition
  8. AND logical condition
  9. OR logical condition

Followers