Operators

  • ARITHMETIC

    Use arithmetic operators (+, -, *, /) to perform arithmetic operations.

    For example:

    SELECT ((unit_cost * interest) + postage)) AS total_price

    FROM purchases

    To use arithmetic operators on non-numeric values, use the CAST function to convert the field value to a numeric.

  • BOOLEAN

    You can filter a table based on multiple conditions using boolean operators AND, OR and NOT to connect multiple predicates in a single WHERE clause.

    For example:

    PROJECT = 'BLK5' AND TARGET = 'MA1'

    Boolean expressions can become very complex. One thing to keep in mind is the fact that AND has precedence over OR, i.e. the AND condition will always be evaluated first. For example, the statement:

    TARGET = 'MA1' OR TARGET = 'MA2' AND END_DEPTH < 150.0

    will in effect be evaluated as

    TARGET = 'MA1' OR (TARGET = 'MA2' AND END_DEPTH < 150.0)

    The order of precedence may be changed by the use of parentheses, eg.:

    (TARGET = 'MA1' OR TARGET = 'MA2') AND END_DEPTH < 150.0

    Use NOT to negate the result of a predicate:

    PROJECT = 'BLK5' AND NOT (TARGET = 'MA1')

  • COMPARISON

    Use comparison operators to compare two like values. Values compared can be field values, literal values, or the results of calculations.

    Operator Meaning
    < Less than
    <= Less than or equal to
    > Greater than
    >= Greater than or equal to
    = Equal to
    != Not equal to
    <> Not equal to (alternative syntax)

    The result of the comparison is a boolean value that can be used in a WHERE clause to filter the data based on the specified criteria.

    For example:

    SELECT

     A.PROJECT PROJ1, A.SUBPROJ SUB1, A.BHID BHID1, A.XCOORD

     X1, A.YCOORD Y1,

     B.PROJECT PROJ2, B.SUBPROJ SUB2, B.BHID BHID2, B.XCOORD

     X2, B.YCOORD Y2

    FROM G_HEADER A, G_HEADER B WHERE A.XCOORD + 50 > B.XCOORD

     AND A.YCOORD + 50 > B.YCOORD

     AND (A.PROJECT <> B.PROJECT

     OR A.SUBPROJ <> B.SUBPROJ

     OR A.BHID <> B.BHID)

Relational Operators