Comparison operators are used to compare data types like integer or text, but they will always return a boolean value. Table 4-9 shows the available comparison operators.

Table 4-9. Comparison Operators

Operator Description
< Less-than
> Greater-than
<= Less-than or equal-to
>= Greater-than or equal-to
= Equivalence, or equal-to
<> or != Inequivalence, or not-equal
Note Not Equal Operator Conventions
 

If you specify the not equal to ( != ) operator in your query, it is converted to <>.

This select statement returns all publisher names except for a publisher named ABC Books.

  SELECT * 
    FROM publish
   WHERE publ_name <> 'ABC Books';
 
  isbn   |    publ_name     | sugg_price
---------+------------------+------------
 2567841 | ODG Books        |     $12.99
 8741205 | Children's Books |     $19.99
  214872 | Young Readers    |      $8.00
  676883 | Reading Rainbow  |     $13.29
(4 rows)   

To see a display of book titles that were published after 1990, use the comparison operators:

Example 4-39. Using Comparison Operators

  SELECT title, cpright_date
   FROM  book
   WHERE cpright_date >= '1990-01-01'; 
   

The result displays:

            title            | cpright_date
-----------------------------+--------------
 Goodnight Moon              | 1991-04-01
 Bartholomew and the Oobleck | 1997-02-01
(2 rows)          

The comparison operators can be used to look at a table with the book titles, author name, and price of books that cost less than or equal to $13.00. Remember that you are accessing columns from two different tables. This operation requires a join. The command to accomplish this is:

Example 4-40. Using Comparison Operators

 
  SELECT p.sugg_price, b.title, b.author_id
   FROM publish p, book b
   WHERE p.isbn = b.isbn
   AND p.sugg_price <= '13.00';
   

The output is:

 sugg_price |        title         | author_id
------------+----------------------+-----------
      $8.00 | Franklin in the Dark |       142
      $4.55 | Goodnight Moon       |       136
     $12.99 | Little Women         |       231
(3 rows)