You can revise the way a table is displayed by using DISTINCT or ORDER BY . DISTINCT returns only one instance of a duplicated value (usually it is the first instance of that value, not the largest or smallest instance). Only columns specified in the query are distinct. NON-selected columns are not compared. ORDER BY will return rows according to descending ( DESC ) or ascending ( ASC - this is the default) order.

In the author column, we have two books written by Dr.Seuss. If we wanted to know who all of the authors are, without any author names repeated, then we can use distinct:

Example 4-23. Using the DISTINCT Clause

   SELECT DISTINCT author_id FROM book;

This statement says to look for distinct instances of the author_id column from the book table and it returns the following:

(5 rows)      

The publisher names are unordered, so we can order them according to ASC order. If you wanted to see an ordered list of the publisher names along with the ISBN numbers of books they have published, use the command:

Example 4-24. Using ORDER BY

   SELECT publ_name, isbn
     FROM publish
    ORDER BY publ_name;

The result of this query outputs:

    publ_name     |  isbn
 ABC Books        |  602071
 ABC Books        |  355184
 Children's Books | 8741205
 ODG Books        | 2567841
 Reading Rainbow  |  676883
 Young Readers    |  214872
(6 rows)

Remember that ascending (ASC) order is the set default for order by. If you want to use descending (DESC) order, the syntax is:

   SELECT colname1, colname2, ...etc.
    FROM tablename
    ORDER BY colname DESC;