CBSE Class 12 Informatics Practices Question 29 of 79

MySQL SQL Revision Tour — Question 22

Back to all questions
22
Question

Question 18

The Doc_name Column of a table Hospital is given below :

Doc_name
Avinash
Hariharan
Vinayak
Deepak
Sanjeev

Based on the information, find the output of the following queries :

(i) SELECT doc_name FROM HOSPITAL WHERE Doc_name like "%v";

(ii) SELECT doc_name FROM HOSPITAL WHERE doc_name like "%e%";

Answer

(i) SELECT doc_name FROM HOSPITAL WHERE Doc_name like "%v";

Output
+----------+
| doc_name |
+----------+
| Sanjeev  |
+----------+
Explanation

The query SELECT doc_name FROM HOSPITAL WHERE Doc_name like "%v"; selects the doc_name from the HOSPITAL table where the Doc_name column ends with the letter "v" using the LIKE operator with the "%" wildcard. This pattern matches any string where "v" is the last character, and any characters can precede it.

(ii) SELECT doc_name FROM HOSPITAL WHERE doc_name like "%e%";

Output
+----------+
| doc_name |
+----------+
| Deepak   |
| Sanjeev  |
+----------+
Explanation

The query SELECT doc_name FROM HOSPITAL WHERE doc_name like "%e%"; selects the doc_name from the HOSPITAL table where the doc_name column contains the letter "e". This is achieved using the LIKE operator with the "%" wildcard before and after the letter "e", which matches any sequence of characters that have "e" in them.