Page 278 - Information_Practice_Fliipbook_Class11
P. 278
For example, to display ID, first name, last name, and the salary of all employees whose first name starts with 'R'.
Solution:
SELECT ID, FName, LName, Salary
FROM EMPLOYEE
WHERE FName LIKE 'R%';
Execution of the above query will produce the output shown in Table 9.30.
Table 9.30: Employees whose first name begins with 'R%'.
+-------+--------+----------+--------+
| ID | FName | LName | Salary |
+-------+--------+----------+--------+
| 10001 | Raj | Reddy | 100000 |
| 10006 | Rajit | Gadh | 60000 |
+-------+--------+----------+--------+
Note that there are two tuples having the first name that matches the pattern 'R%'(FName starting with R).
Query: Display ID, first name, last name, and the salary of employees whose first name starts with 'R' and salary in
the sixty thousand range, i.e., a five-digit number beginning 6.
Solution:
SELECT ID, FName, LName, Salary
FROM EMPLOYEE
WHERE FName LIKE 'R%' AND Salary LIKE '6____';
Execution of the above query will produce the output shown in Table 9.31.
Table 9.31: Employees whose first name begins with 'R%' and have a salary in the range of sixty thousand.
+-------+--------+----------+--------+
| ID | FName | LName | Salary |
+-------+--------+----------+--------+
| 10006 | Rajit | Gadh | 60000 |
+-------+--------+----------+--------+
Query: Display the employee ID and first name of all employees whose first name contains two a's or two e's.
SELECT ID, FName
FROM EMPLOYEE
WHERE FName LIKE '%a%a%' OR FName LIKE '%e%e%';
Execution of the above query will produce the output shown in table Table 9.32.
Table 9.32: Employees whose first name contains two a's or two e's.
+-------+--------+
| ID | FName |
+-------+--------+
| 10001 | Taran |
| 10008 | Naval |
| 10009 | Naveen |
| 10010 | Savita |
+-------+--------+
Query: Display the first name, last name, and date of birth of all employees who were born in 1980.
Solution:
SELECT FName, LName, DOB
FROM EMPLOYEE
WHERE DOB LIKE '1980______';
or
SELECT FName, LName, DOB
FROM EMPLOYEE
WHERE DOB LIKE '1980%';
264 Touchpad Informatics Practices-XI

