DML Commands
DML Commands
DML Commands
basis of conditions.
Syntax:
the operation.
Example:
1.SELECT *FROM emp
WHERE ecity = ’pune' AND age >30;
2. select * from emp where(ecity='pune' and did=1)or
(age<33);
LIKE Operator- search for a specified pattern in a column
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
SQL Wildcards
SQL wildcards can substitute for one or more
characters when searching for data in a database.
SQL wildcards must be used with the LIKE operator .
Wildcard Description
% A substitute for zero or more characters
_ A substitute for exactly one character
LIKE Operator- Example
"Persons" table
P_Id LastName Address
1 Heena Pune
2 Savita Pune
3 Sarika Bombay
table_name;
Example
SELECT distinct(Address) from emp;
IN Operator
The MySQL IN condition is used to reduce the use of
multiple OR conditions in a SELECT, INSERT, UPDATE
and DELETE statement.
The IN operator allows you to specify multiple values in a
WHERE clause.
Syntax
SELECT column_name(s) FROM table_name
WHERE column_name IN (value1,value2,...)
Example
SELECT * FROM emp WHERE city IN
('Pune',mumbai');
NULL Operator-
To test if a value is NULL you cannot use =,
because every NULL is considered distinct from
every other one. Must use "IS NULL" or "IS NOT
NULL“
Syntax
SELECT Attr_List FROM table_name
WHERE Attr_name IS NULL;
Example
1. SELECT * FROM Stud WHERE city is null;
2. SELECT * FROM Stud WHERE city is not null;
Not Equal operator
MySQL Not Equal is an inequality operator that
used for returning a set of rows after comparing
two expressions that are not equal. The MySQL
contains two types of Not Equal operator, which
are (< >) and (! =).
Example:
SELECT * FROM emp WHERE city <> “pune";
SELECT * FROM emp WHERE city != “pune";
Between Operator
The MYSQL BETWEEN condition specifies how to
retrieve values from an expression within a specific
range. It is used with SELECT, INSERT, UPDATE
and DELETE statement.
Example:
SELECT * FROM stud
WHERE grade BETWEEN 70 AND 80;
Aggregate Functions
MySQL aggregate functions retrieve a single value
after performing a calculation on a set of values.
In general, aggregate functions ignore null values.
• Used to find the minimum value of a
Min certain column
• Used to find the maximum value of a
Max certain column
• Used to calculate the average value of
Sum the numeric type
• Used to calculate the sum of all selected
Avg columns
• Used to Count the number of rows in a
Count database table
Avg(),Min(),Max(),Sum()
Syntax
SELECT AVG( column_name) FROM table_name;
Example
SELECT AVG(Marks) FROM Stud;
Syntax
SELECT Min( column_name) FROM table_name;
Example
SELECT Min(Marks) FROM Stud;
Syntax
SELECT COUNT( column_name) FROM table_name;
Example:
SELECT ename, did, SUM(salary) AS "Total dept
salary" FROM emp GROUP BY did having
sum(salary)>50000;
MySQL first function
By default, the UNION operator removes duplicate rows even if you don’t