SQL Where Comparison .

Using Comparison operators with WHERE statement.

  • SQL provides a variety of operators and keywords for expressing the search condition, which include these:
  • Comparison operators (=, <, >, and so on)

    Possible comparision operators:
    Operator Meaning
    = equal to
    > greater than
    < less than
    >= greater than or equal to
    <= less than or equal to
    <> or != not equal to
    MySQL, Oracle, SQL server, PostgreSQL:
    select isbn_no "ISBN where order is over $100" ,
      ITEM_QTY * price "Order in $"
      from order_books
      where ITEM_QTY * price > 100 ;
    The result should be:
    ISBN where order is over $100 Order in $
    1861002025 190
    0764579088 140
    0201703092 390
    1861002025 190
  • To select data from columns containing text use always text surrounded with '(single quotes) for the selection.
    MySQL, Oracle, SQL server, PostgreSQL:
    select * from us_states  
       where US_STATE_CD>='CA'  and US_STATE_CD<='CZ'  
    The result should be:
    CA California
    CO Colorado
    CT Conneticut
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.