Basic Lab For MySQL
Basic Lab For MySQL
Basic Lab For MySQL
Systems(DBMSs)
Lab manual : 4
2. After creating the tables, populate each table with the following data:
EMPLOYEE TABLE:
EMP_ID
EMP_FNAME
EMP_LNAME
MIT/1999/1
MIT/1999/2
BINIAM
MEZGEBO
GEBREKIDAN
HAILU
MIT/1999/3
MIT/2004/1
TILAHUN
KIFLE
KIROS
BERNAHE
MIT/2004/2
TEKLAY
GEBREZGIABHER
MIT/1999/5
SEYUM
TESFAY
MIT/1999/6
KIROS
SYUM
MIT/1999/7
AKLIL
ZENEBE
MIT/1999/8
BARAKI
HALEFOM
MIT/1999/9
ASSEFA
G/WERGIS
MIT/1999/10
TEKLEMARIAM
TSEGAY
MIT/2000/1
ASMELASH
TSEGAY
MIT/2001/1
AWEL
NURHUSEN
MIT/2001/2
MUNIR
MIT/2000/2
MELES
YFTER
MIT/2000/3
GIRMAY
TE-AMRAT
MIT/2000/4
KIROS
ABREHA
MIT/2000/5
MIT/2000/6
BIRHANE
FISEHA
G/HAWERIA
WELDAY
MIT/2000/7
SIRAJ
FILUM
MIT/2000/8
MIZAN
ABRHA
MIT/2000/9
MEARG
AREGAWI
SIRAJ
MIT/2002/1
FREWEINI
GEBRU
EMP_GENDER
EMP_AGE
EMP_SALARY
26
2800.0000
200
1900.0000
30
2000.0000
45
2010.0000
26
900.0000
29
1900.0000
22
1700.0000
20
1200.0000
18
12000.0000
15
13000.0000
29
11000.0000
310
1982.0000
20
1900.0000
27
4000.000
18
21000.0000
15
31000.0000
29
1000.0000
301
2982.0000
28
1900.0000
20
1980.000
DEPARTMENT TABLE:
EMP_ID
DEPT_CODE
DEPT_NAME
MIT/1999/1
CSE
MIT/1999/2
IT
Information Technology
MIT/1999/3
IT
INFORMATION TECHNOLOGY
MIT/1999/4
IT
INFORMATION TECHNOLOGY
MIT/1999/5
IT
MIT/1999/6
ECE
MIT/1999/7
CSE
MIT/2000/1
CSE
MIT/2001/1
CSE
MIT/2001/2
CSE
MIT/2004/2
INFORMATION TECHNOLOGY
CSE
MIT/2000/2
ECE
MIT/2000/3
CSE
MIT/2000/4
EEE
MIT/2000/5
ECE
MIT/2000/6
ECE
MIT/2000/7
EEE
MIT/2000/8
EEE
MIT/2000/9
ECE
MIT/2004/1
ECE
COURSE TABLE:
EMP_ID
COURSE_CODE
MIT/2004/2
MIS
CREDIT_HOURS
3
COURSE_NAME
MANAGEMENT INFORMATION SYSTEMS
MIT/1999/2
SYSTEMS
DBMS
DATABASE MANAGEMENT
MIT/2004/1
DS
DATA STRUCTURES
MIT/1999/5
RAD
MIT/1999/6
SAS
MIT/1999/7
DC
DATA COMMUNICATIONS
MIT/2000/1
CM
COMPUTATIONAL METHODS
MIT/2000/2
PS
POWER SYSTEMS
MIT/2000/5
MS
MICROWAVE SYSTEMS
MIT/2000/6
DSP
MIT/2000/7
MC
MICROCONTROLLERS
16. Now rewrite the query in 15 in a way that it will retrieve a list of unique departments only.
17. Remember that using the COUNT (*) aggregate function returns a count of all rows in a table.
Write a query to return a count of the rows in the COURSES table.
18. If you want to avoid using an asterisk with COUNT (*), it is possible to use select column name,
COUNT (column name).Write the query number 17 using this method. Is there a difference with the
former one?
19. LIKE statement allows you to use wildcards in your comparisons. Using LIKE statement write a
query that lists the details of all employees whose first name start with the letter M
20. IN also allows you to compare a single column to a list of values. For example, if you want to
retrieve a list of all employees whose age is 20, 25, or 30. Write a query using IN that can accomplish
this task.
21. BETWEEN allows you to check if a column contains a value that is greater than or equal to one
value and less than or equal to another. Write a query that lists all employees whose age is between 20
and 30.
22. Write a query that returns the details of male employees who are elder than 30 and with salary
greater than or equal to 1800.00birr.
23. Write a query that returns the details of employees who are not elder than 30 and whose salary is
not equal to 1800.00birr.
*24. Write a query that retrieves the names of employees whose salary is greater than mine. {You will
get a bonus for this.}