How can we use ASCII() function with MySQL WHERE clause?

MySQLMySQLi Database

While using the ASCII() function with WHERE clause, the output returns by it will depend upon the condition given in WHERE clause. For example, suppose we have a table named ‘Student’ and we want to get the number code, higher than 65, of the first characters of the names of the students. The query for this can be written as follows −

mysql> Select * from student;
+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 1    | Gaurav  | Delhi   | Computers |
| 2    | Aarav   | Mumbai  | History   |
| 15   | Harshit | Delhi   | Commerce  |
| 20   | Gaurav  | Jaipur  | Computers |
+------+---------+---------+-----------+
4 rows in set (0.10 sec)

mysql> Select Name, ASCII(Name) As 'ASCII VALUE OF 1st Character' From Student WHERE ASCII(Name)>65;
+---------+------------------------------+
| Name    | ASCII VALUE OF 1st Character |
+---------+------------------------------+
| Gaurav  |         71                   |
| Harshit |         72                   |
| Gaurav  |         71                   |
+---------+------------------------------+
3 rows in set (0.00 sec)
raja
Published on 19-Feb-2018 17:49:22
Advertisements