Page 272 - PYTHON-12
P. 272
For example,
• mysql> SELECT * FROM student WHERE Name LIKE “D%”;
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no Stream
2. Deep Singh M 98 22-Aug-1996 8988886577 Commerce
6. Diksha Sharma F 80 17-Dec-1999 9897666650 Humanities
2 rows in a set (0.02 sec)
The above command shall display those records where the name begins with character ‘D’.
• mysql> SELECT * FROM student WHERE Name LIKE “%a”;
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no Stream
3. Ankit Sharma M 76 02-Feb-2000 NULL Science
4. Radhika Gupta F 78 03-Dec-1999 9818675444 Humanities
6. Diksha Sharma F 80 17-Dec-1999 9897666650 Humanities
8. Akshay Dureja M 90 05-May-1997 9560567890 Commerce
4 rows in a set (0.02 sec)
The above command shall display the records for those students whose name ends with the letter
‘a’.
• mysql> SELECT * FROM student WHERE Name LIKE “%e%;
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no Stream
2. Deep Singh M 98 22-Aug-1996 8988886577 Commerce
5. Payal Goel F 82 21-April-1998 9845639990 Vocational
7. Gurpreet Kaur F NULL 04-Jan-2000 7560875609 Science
8. Akshay Dureja M 90 05-May-1997 9560567890 Commerce
9. Shreya Anand F 70 08-Oct-1999 NULL Vocational
10. Prateek Mittal M 75 25-Dec-2000 9999967543 Science
6 rows in a set (0.02 sec)
As the resultant table shows, the above command displays the records of all the students whose
Name contains the character ‘e’ in it.
• mysql> SELECT * FROM student WHERE Name LIKE “_e%;
Resultant table: student
Computer Science with Python–XII 12.42 1 row in a set (0.02 sec) 22-Aug-1996
Name
DOB
Rollno
2.
Deep Singh
This command shall display the Rollno, Name and DOB of all the students whose Name contains
the letter ‘e’ at the second place.
• mysql> SELECT Rollno, Name, Marks, DOB FROM student WHERE Name LIKE “%r_ _”;