O'Reilly logo

Discovering SQL: A Hands-On Guide for Beginners by Alex Kriegel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required