SQL Tutorial SQL Advanced SQL Database SQL References

SQL - Multiply (*) Operator



The SQL * (multiply) operator is used to multiply two values. It operates on numerical values.

The example below describes how to use multiply 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 multiplication of Var1 and Var2 column values is greater than 100, the SQL code is given below.

    SELECT * FROM Sample
    WHERE Var1 * Var2 > 100;
    

    The query will produce following result:

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

    SELECT *, (Var1 * Var2) AS Prod FROM Sample;
    

    The query will produce following result:

    DataVar1Var2Prod
    Data110110
    Data215230
    Data320360
    Data4254100
    Data5305150
    Data6356210
  • Using with UPDATE Clause: To update the column Var1 with the product 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
    Data1101
    Data2302
    Data3603
    Data41004
    Data51505
    Data62106
  • Using with values: To multiply two values, we can simply use SELECT statement:

    SELECT 50 * 30;
    

    The query will produce following result:

    1500
    

❮ SQL Operators