MySQL - Multiply (*) Operator
The MySQL * (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:
Data | Var1 | Var2 |
---|---|---|
Data1 | 10 | 1 |
Data2 | 15 | 2 |
Data3 | 20 | 3 |
Data4 | 25 | 4 |
Data5 | 30 | 5 |
Data6 | 35 | 6 |
-
Using with WHERE Clause: To select records of table where multiplication of Var1 and Var2 column values is greater than 100, the query is given below.
SELECT * FROM Sample WHERE Var1 * Var2 > 100;
The query will produce following result:
Data Var1 Var2 Data5 30 5 Data6 35 6 -
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:
Data Var1 Var2 Prod Data1 10 1 10 Data2 15 2 30 Data3 20 3 60 Data4 25 4 100 Data5 30 5 150 Data6 35 6 210 -
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:
Data Var1 Var2 Data1 10 1 Data2 30 2 Data3 60 3 Data4 100 4 Data5 150 5 Data6 210 6 -
Using with values: To multiply two values, we can simply use SELECT statement:
SELECT 50 * 30;
The query will produce following result:
50 * 30 1500
❮ MySQL Operators