Computer >> Computer tutorials >  >> Programming >> MySQL

How can SELECT, without reference to any table, be used to calculate expression in MySQL?


With the help of following MySQL statement, we can use SELECT to calculate the expression −

SELECT expression;

The above statement is having no reference to any table. Followings are some examples −

mysql> Select 10 DIV 5;
+----------+
| 10 DIV 5 |
+----------+
|        2 |
+----------+
1 row in set (0.06 sec)

mysql> Select 10*5;
+------+
| 10*5 |
+------+
|   50 |
+------+
1 row in set (0.00 sec)

mysql> Set @var1 = 100, @var2 = 200;
Query OK, 0 rows affected (0.00 sec)

mysql> Select @Var1+@Var2;
+-------------+
| @Var1+@Var2 |
+-------------+
|         300 |
+-------------+
1 row in set (0.00 sec)