SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite - Add (+) Operator



The SQLite + (add) operator is used to add two values. It operates on numerical values.

The example below describes how to use add operator in various conditions:

Example:

Consider a database table called Sample with the following records:

DataVar1Var2
Data1101
Data2152
Data3203
Data4254
Data5305
Data6356

  • Using with WHERE Clause: To select records of table where sum of Var1 and Var2 column values is greater than 25, the query is given below:

    SELECT * FROM Sample
    WHERE Var1 + Var2 > 25;
    

    The query will produce following result:

    DataVar1Var2
    Data4254
    Data5305
    Data6356
  • Using with AS Clause: The sum of Var1 and Var2 column values can be displayed in a different column using AS clause:

    SELECT *, (Var1 + Var2) AS SUM FROM Sample;
    

    The query will produce following result:

    DataVar1Var2SUM
    Data110111
    Data215217
    Data320323
    Data425429
    Data530535
    Data635641
  • Using with UPDATE Clause: To update the column Var1 with the sum of columns Var1 and Var2, the query is given below:

    UPDATE Sample
    SET Var1 = Var1 + Var2;
    
    --See result
    SELECT * FROM Sample;
    

    The query will produce following result:

    DataVar1Var2
    Data1111
    Data2172
    Data3233
    Data4294
    Data5355
    Data6416
  • Using with values: To add two values, we can simply use SELECT statement:

    SELECT 30 + 50;
    

    The query will produce following result:

    30 + 50
    80

❮ SQLite Operators