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


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)

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 30-Jan-2020

244 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements