B.E.
(E&TC) – 2019 Pattern Database Management Lab
Group: A
Experiment No.3
Design and develop at least 5 SQL queries for suitable database application using
SQL DML statements: Insert and select with operators and functions.
Roll Number
Date of Performance
AIM: Design and develop at least 5 SQL queries for suitable database application using SQL
DML statements: Insert and Select with operations and functions.
OBJECTIVES: To understand and demonstrate DML statements on various SQL objects.
SOFTWARE/TOOLS: MySQL Server, MySQL Workbench, and Command Line Client.
THEORY: -
1) MySQL INSERT Query:
Syntax:
INSERT INTO table_name(field1, field2,...fieldN) VALUES (value1, value2,…..valusN);
2) MySQL UPDATE Query:
Syntax:
UPDATE table_name SET field1=new-value1, field2=new-value2[WHERE Clause];
3) MySQL DELETE Query:
Syntax:
DELETE FROM table_name [WHERE Clause];
4) MySQL SELECT Query:
Syntax:
SELECT field1, field2,...fieldN from table WHERE Clause;
5) MySQL UPDATE Query:
Syntax:
UPDATE table_name SET field=new-value1 [WHERE Clause];
10
B.E. (E&TC) – 2019 Pattern Database Management Lab
Aggregation Operation
Name Description
AVG() Return the average value of the Arguments
BIT_AND() Return bitwise and
BIT_OR() Return bitwise or
BIT_XOR() Return bitwise xor
COUNT(DISTINCT) Return the count of a number of different values
COUNT() Return a count of the number of rows returned
GROUP_CONCAT() Return a concatenated string
MAX() Return the maximum value
MIN() Return the minimum value
STD() Return the population standard derivation
STDDEV_POP() Return the population standard deviation
STDDEV_SAMP() Return the sample standard deviation
STDDEV() Return the population standard derivation
SUM() Return the sum
Comparison Functions and Operators
Name Description
BEETWEEN .. AND Check whether a value is within a range of values
= Equal operator
<=> NULL-safe equal to operator
> Greater than operator
<= Greater than or equal operator
GREATEST() Return the largest argument
IN() Check whether a value is within a set of values
IS Test a value against a Boolean
< Less than operator
<= Less than or equal operator
LIKE Simple pattern matching
OR Check whether a value is within a range of values
11
B.E. (E&TC) – 2019 Pattern Database Management Lab
Set Operator:
1. Union
UNION is used to combine the results of two or more Select statements. However it will eliminate
duplicate rows from its result set. In case of union number of columns and datatype must be same
in both the tables.
Union SQL query will be,
select * from FirstUNION select * from second;
2. Union All
This operation is similar to Union. But it also shows the duplicate rows.
Union All query will be like,
select * from First UNION ALL select * from second;
3. Intersect
Intersect operation is used to combine two SELECT statements, but it only retuns the records
which are common from both SELECT statements. In case of Intersect the number of columns and
datatype must be same. MySQL does not support INTERSECT operator.
Intersect query will be,
SELECT a.x, a.y FROM table_a a JOIN table_b b ON a.x = b.x AND a.y = b.y;
4. Minus
Minus operation combines result of two Select statements and return only those result belongs to
first set of result. MySQL does not support INTERSECT operator.
Minus query will be,
SELECT a.x, a.y FROM table_a a LEFT JOIN table_b b ON a.x = b.x AND a.y=b.y WHERE b.x IS NULL;
CONCLUSION:
QUESTIONS:
1. What is the difference between DDL and DML?
2. What are the differences between union and union all?
3. What are the differences between Minus and Intersect?
12
B.E. (E&TC) – 2019 Pattern Database Management Lab
REFERENCES:
[1] Database System Concepts 7th Edition Avi Silberschatz, Henry F. Korth, S Sudarshan.
Mc Graw Hill Publication. Chapter-03, Page No-65-111
Marks (Out of 20) Signature of Faculty with Date
MR (6) MP (6) MU (8) Total (20)
MR – Marks for Regularity, MP – Marks for Presentation, MU – Marks for
Understanding
13