Using the entire expression in MySQL WHERE clause?


Let us see an example and create a −

mysql> create table DemoTable1406
   -> (
   -> Value int
   -> );
Query OK, 0 rows affected (0.47 sec)

Insert some records in the table using insert −

mysql> insert into DemoTable1406 values(10);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1406 values(50);
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1406 values(40);
Query OK, 1 row affected (0.07 sec)
mysql> insert into DemoTable1406 values(30);
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select −

mysql> select * from DemoTable1406;

This will produce the following output −

+-------+
| Value |
+-------+
|    10 |
|    50 |
|    40 |
|    30 |
+-------+
4 rows in set (0.00 sec)

Following is the query to use the entire expression −

mysql> select Value+10 as ExpectedValue
   -> from DemoTable1406
   -> where Value+10=40;

This will produce the following output −

+---------------+
| ExpectedValue |
+---------------+
|            40 |
+---------------+
1 row in set (0.00 sec)

Updated on: 11-Nov-2019

67 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements