SQL OPERATORS: AGENTS OF CHANGE

Operators are fulfilling an important go-between function, connecting data, comparing data, and changing behavior of SQL statements. Operators in SQL are defined as symbols and keywords that are used to specify an action to be performed on one or more expressions called operands (the parts on which the operator operates).

All operators can be split into two broad categories:

  • Unary operators — Applied to only one operand at a time; a typical format is <operator><operand>.
  • Binary operators — Applied to two operands at a time; they usually appear in the format <operand><operator><operand>.

Arithmetic and String Concatenation Operators

Arithmetic operators, as the name implies, are used for arithmetic computations. The use of the arithmetic operators is very intuitive (elementary school stuff), and they can be used in virtually every clause of the SQL statement. Table 2-10 provides a selected list of arithmetic operators.

TABLE 2-10: Selected Arithmetic Operators

OPERATOR DESCRIPTION
+ Addition: Adds two numbers or (in the case of Microsoft SQL Server) concatenates strings. With this exception, the usage is identical across all three databases. Valid for all RDBMSs.
Subtraction: Subtracts one numeric value from another. The usage is identical across all RDBMSs. It is also used as a sign identity or unary negation operator.
* Multiplication: Multiplies one number by another. The usage is identical across all RDBMSs.
/ Division: Divides ...

Get Discovering SQL: A Hands-On Guide for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.