Sunday, September 20, 2009

SQL functions

Functions are a very powerful feature of SQL

They can be used to do the following:
  • Calculations on data
  • Modify individual data items
  • Manipulate output for groups of rows
  • Format dates and numbers for display
  • Convert column data types
  • SQL functions sometimes take arguments and always return a value
Two Types of SQL Functions :



  • Single-Row Functions
    – These functions operate on single rows only and return one result per row. There are different types of single-row functions.
  • future posts covers the following ones:
    • Character
    • Number
    • Date
    • Conversion
    • General
  • Multiple-Row Functions
    – Functions can manipulate groups of rows to give one result per group of rows. These functions are also known as group functions

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 ;

Followers