Page 168 - Informatics_Practices_Fliipbook_Class12
P. 168
To display the first name, last name, and date of birth of all employees born between the years 1985 to 1990.
SELECT FName, LName, DOB
FROM EMPLOYEE
WHERE DOB BETWEEN '1985-01-01' AND '1990-12-31';
Execution of the above statement will produce the output shown in Table 4.17 .
FName LName DOB
Muskan Taneja 1990-01-25
Hiten Oberoi 1985-06-24
Anshul Verma 1990-01-01
Savita Ambedkar 1987-07-11
Table 4.17 Employees whose date of birth is between '1985-01-01' and '1990-12-31'
Note that in the above example, the date appears in YYYY-MM-DD format. We can display a date in DD/MM/YYYY
format as follows:
SELECT FName, LName, DATE_FORMAT(DOB,'%d/%m/%Y') AS DOB
FROM EMPLOYEE
WHERE DOB BETWEEN '1985-01-01' AND '1990-12-31';
Execution of the above statement will produce the output shown in Table 4.18.
FName LName DOB
Muskan Taneja 25/01/1990
Hiten Oberoi 24/06/1985
Anshul Verma 01/01/1990
Savita Ambedkar 11/07/1987
Table 4.18 Employees whose date of birth is between '1985-01-01' and '1990-12-31'
Query: Display the first name, last name, and date of birth of all employees, except those who were born between the
years other than 1985 to 1990.
Solution: To answer the above query, we use NOT operator before BETWEEN operator as follows:
SELECT FName, LName, DOB
FROM EMPLOYEE
WHERE DOB NOT BETWEEN '1985-01-01' AND '1990-12-31';
Execution of the above statement will produce the output shown in Table 4.19.
FName LName DOB
Raj Reddy 1980-06-13
Dhiraj Bora 1975-09-30
Rajit Gadh 1960-05-07
Taran Adarsh 1965-01-13
Naval Dhingra 1975-08-04
Naveen Basra 1980-09-24
Table 4.19 Employees whose date of birth is outside the interval ['1985-01-01', '1990-12-31']
154 Touchpad Informatics Practices-XII

