0% found this document useful (0 votes)
17 views

Lab Report 4 Final

dbms lab report 4 in mysql

Uploaded by

it22016
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab Report 4 Final

dbms lab report 4 in mysql

Uploaded by

it22016
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Mawlana Bhashani Science and Technology University

Santosh, Tangail-1902

Department of Information and Communication Technology

Lab Report 04
Course Title: Database Management System Lab
Course Code: ICT-2108
Lab Report on: Basic Queries in MySQL

Submitted By Submitted To

Name: Md. Faim Montasir Dr. Md. Abir Hossain


ID: IT-22016 Associate Professor
2nd Year, 1st Semester Dept. of ICT, MBSTU
Session: 2021-2022
Dept. of ICT, MBSTU

Date of Performance: 19-03-2024 Date of Submission: 25-03-2024

Experiment No: 04
Experiment Name: Basic Queries in MySQL

Objectives: The main objective of this experiment is to use some basis queries of
MySQL. We will learn how to use query with different conditions to find desire output
from one or more database tables.
Required Instruments:
1. MySQL 8.3 Command line Client.

Queries:

The Cartesian product of the instructor relation with the teaches relation.
SQL expression: select name ,course_id from instructor ,teaches where
instructor.ID=teaches.ID;

Find only instructor names and course identifiers for instructors in the ICT department.
SQL expression: select name, course id from instructor, teaches where
instructor.ID= teaches.ID and instructor.dept_name = 'ICT';

If we want the attribute name name to be replaced with the name instructor_name , we can
rewrite the preceding query as:
SQL expression: select name as instructor_name, course id from
instructor, teaches where instructor.ID= teaches.ID;
For all instructors in the university who have taught some course, find their names and the
course ID of all courses they taught.
SQL expression: select T.name, S.course_id from instructor as T,
teaches as S where T.ID= S.ID;

Find the names of all instructors whose salary is greater than at least one instructor in the ICT
department.
SQL expression: select distinct T.name from instructor as T,
instructor as S where T.salary > S.salary and S.dept_name = 'ICT';

Find the names of all departments whose building name includes the substring '1’.
SQL expression: select dept name from department where building like
'%1%';
The asterisk symbol “ * ”can be used in the select clause to denote “all attributes. ”
SQL expression: select instructor.* from instructor, teaches where
instructor.ID= teaches.ID;

The order by clause causes the tuples in the result of a query to appear in sorted order.
SQL expression: select name from instructor where dept_name = 'ICT'
order by name;

We wish to list the entire instructor relation in descending order of salary. If several
instructors have the same salary, we order them in ascending order by name.
SQL expression: select * from instructor order by salary desc, name
asc;
If we wish to find the names of instructors with salary amounts between 30,000 and 45,000.
SQL expression: select name from instructor where salary between
30000 and 45000;

The set of all courses taught in the Fall 2017 semester.


SQL expression: select course_id from section where semester = 'Fall'
and year= 2017;

The set of all courses taught in the Spring 2018 semester.


SQL expression: select course_id from section where semester =
'Spring' and year= 2018;

To find the set of all courses taught either in Fall 2017 or in Spring 2018, or both.
SQL expression: (select course_id from section where semester = 'Fall'
and year= 2017) union (select course_id from section where semester
= 'Spring' and year= 2018);

To find the set of all courses taught in both the Fall 2017 and Spring 2018.
SQL expression: (select course_id from section where semester = 'Fall'
and year= 2017) intersect (select course_id from section where
semester = 'Spring' and year= 2018);

To find all courses taught in the Fall 2017 semester but not in the Spring 2018 semester.
SQL expression: (select course_id from section where semester =
'Fall' and year= 2017) except (select course_id from section where
semester = 'Spring' and year= 2018);
[outputs on the next page]

If we want to retain duplicates, we must write except all in place of except.


SQL expression: (select course_id from section where semester = 'Fall' and year= 2017)
except all (select course_id from section where semester = 'Spring' and year= 2018);
To find all instructors who appear in the instructor relation with null values for salary.
SQL expression: select name from instructor where salary is null;
Find the average salary of instructors in the ICT department.
SQL expression: select avg (salary) from instructor where dept_name = 'ICT';
Find the average salary in each department.
SQL expression: select dept_name, avg (salary) as avg_salary from instructor group by
dept_name;
Find the average salary of all instructors from ICT dept.
SQL expression: select avg (salary) from instructor where dept_name = ‘ICT’;
Find average salary as avg_salary of ICT department .
SQL expression: select avg (salary) as avg_salary from instructor where dept_name =
‘ICT’ ;
Find the total number of instructors who teach a course in the Spring 2018 semester.
SQL expression: select count(distinct ID) from teaches where semester = 'Spring' and year =
2018;
Find the number of tuples in the course relation.
SQL expression: select count (*) from course;
Find the total salary.
SQL expression: select sum (salary) from instructor;

Find the departments name and average salary where the average salary of the instructors is
more than 31,000.
SQL expression: select dept_name, avg(salary) as avg_salary from instructor group by
dept_name having avg(salary)>31000;
The names of instructors whose names are neither “MD.Alamin” nor “Fahim”.
SQL expression: select distinct name from instructor where name not in ('MD.Alamin' ,
'Fahim');

Discussion:
By the above queries, we can easily find out desired records and attributes. We can also use
arithmetic expressions, string operations, SQL aggregation functions etc. to find set of data as
per our expectations.

You might also like