DBMS L2 v1
DBMS L2 v1
Assistant Engineer,
System DESCO
Structured Query
Language(SQL)
Data
Manipulation
Language
INSERT, UPDATE, DELETE
UPDATE: This command modifies data of
one or more records. An update command
syntax is UPDATE [table name] SET
[column name = value] where [condition].
Language
name] [column(s)] VALUES [value(s)].
Operators <
=
Less Than
Equal
<>, != Not Equal
>= Greater Than or Equal
<= Less Than or Equal
IN, NOT IN Check the attribute value matches with Specific
values.
LIKE, NOT LIKE String Matching
BETWEEN…AND Check the whether value is between the range
IS NULL, IS NOT Check the whether value is NULL
NULL
Operator Operation
> Greater Than
Operators <
=
Less Than
Equal
<>, != Not Equal
>= Greater Than or Equal
<= Less Than or Equal
IN, NOT IN Check the attribute value matches with Specific
values.
LIKE, NOT LIKE String Matching
BETWEEN…AND Check the whether value is between the range
IS NULL, IS NOT Check the whether value is NULL
NULL
The LIKE operator
Practice Problem
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
Practice Problem
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
SELECT *
FROM STUDENT
WHERE city=‘Dhaka’
sid first_Name last_Name Gender city mobile no
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
Student
sid first_Name last_Name Gender city mobile no
11 Ashik Al Amin M Khulna 01212458695
21 Arif Zaman M Sylhet 01562400523
Practice Problem
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
SELECT *
From Students
Where first_name like = ‘A%’
sid first_Name last_Name Gender city mobile no
11 Ashik Al Amin M Khulna 01212458695
21 Arif Zaman M Sylhet 01562400523
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
SELECT *
From Students
Where first_name like ‘A%’
sid first_Name last_Name Gender city mobile no
11 Ashik Al Amin M Khulna 01212458695
21 Arif Zaman M Sylhet 01562400523
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
Practice Problem
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
Practice Problem
32 Dipta Roy M Dhaka 01457203156
43 Fatema Farzana F Dhaka 06845201412
54 Saima Akhtar F Rajshahi 04875265489
Problem 1
SELECT MAX(mark)
FROM RESULT
WHERE course = ‘CSE’
• Result(sid, course, grade, mark)
table contains the marks and grade
of all courses for each students.
• Write a query to find the highest
mark of each course.
Problem 2
SELECT course, MAX(mark)
FROM RESULT
Group by course
Aggregate
Functions in
SQL
Interesting Problem
q How to get distinct records from the Employees
table without using distinct keyword?
id dept salary
1 it 50 dept Max(Salary)
2 hr 40 it 85
3 hr 70 hr 70
4 finance 75 finance 75
5 it 85
6 finance 65
7 hr 35 Display the dept and id of
8 it 45 highest paid employee of
9 hr 67
each department
Problem
id dept salary dept Max(Salary)
1 it 50 it 85
2 hr 40 hr 70
3 hr 70 finance 75
4 finance 75
5 it 85
SELECT dept, id
6 finance 65
FROM EMPLOYEE
7 hr 35 WHERE (dept, salary) in (SELECT dept, max(salary)
8 it 45 FROM EMPLOYEE
GROUP BY DEPT )
9 hr 67
DML Again
Delete, Update
Practice Problem
• Update the students’ grade to
UPDATE RESULT
‘A+’ who got 70 to above
SET GRADE = ‘A+’
marks.
WHERE marks>=70
Practice Problem
• Delete the students’ record
who got ‘F’ grade. DELETE FROM RESULT
WHERE grade = ‘F’
Any Questions?
Thanks!