際際滷

際際滷Share a Scribd company logo
DML COMMANDS
BY Ms. Sonali Sonavane
INSERT Command
 MySQL INSERT statement is used to store or add data in MySQL
table within the database.
 We can perform insertion of records in two ways using a single
query in MySQL:
 Insert record in a single row
 Insert record in multiple rows
Syntax:
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES ( value1, value2,...valueN );
Example:
INSERT INTO People (id, name, occupation, age)
VALUES (101, 'Peter', 'Engineer', 32);
遺看稼岳
 Inserting Multiple records into table
Syntax:
INSERT INTO table_name VALUES
( value1, value2,...valueN ),( value1, value2,...valueN ),
...........,(value1, value2,...valueN );
Example:
INSERT INTO People VALUES (102, 'Joseph', 'Develope
r', 30),(103, 'Mike', 'Leader', 28),
(104, 'Stephen', 'Scientist', 45);
遺看稼岳
 If we want to store records without giving all fields,
we use the following partial field statements. In such
case, it is mandatory to specify field names.
Example:
INSERT INTO People (name, occupation)
VALUES ('Stephen', 'Scientist'), ('Bob', 'Actor');
Update command
 MySQL UPDATE query is a DML statement used to
modify the data of the MySQL table within the
database.
 The UPDATE statement is used with the SET and
WHERE clauses. The SET clause is used to change
the values of the specified column. We can update
single or multiple columns at a time.
遺看稼岳
Syntax:
UPDATE table_name SET column_name1 = new -
value1,column_name2=new-value2, ...
[WHERE Clause]
Example:
1. update stud set city='pune' where name='aarti';
(Only city field of row having name as aarti will be changed as
pune)
2. . update stud set city='pune'
(city field of All row will be changed as Pune)
DELETE Command
 MySQL DELETE statement is used to delete data from the
MySQL table within the database.
 By using delete statement, we can delete records on the
basis of conditions.
Syntax:
DELETE FROM table_name WHERE (Condition specified);
Example:
delete from stud where grade='72';
DELETE FROM Stud;
DQL Commands:SELECT
 The MySQL SELECT statement is used to fetch data from the one or
more tables in MySQL. We can retrieve records of all fields or
specified fields.
Syntax:
SELECT column list
FROM table
[WHERE conditions];
Example:
1. Select rno, name from stud;
2. Select * from stud;
3. Select * from stud where grade>60;
4. Select grade from Stud where name=aarti;
Where clause
 MySQL WHERE Clause is used with SELECT, INSERT,
UPDATE and DELETE clause to filter the results.
 It specifies a specific position where you have to do 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
P_Id LastName Address
1 Heena Pune
2 Savita Pune
3 Sarika Bombay
"Persons" table
We use the following SELECT statement:
1. SELECT LastName from Person where LastName like S%
2.SELECT ename FROM emp WHERE address LIKE _________90';
3. SELECT ename FROM emp WHERE ecity NOT LIKE mum%';
Order By- clause
 The ORDER BY keyword is used to sort the result-set by a specified column.
 The ORDER BY keyword sort the records in ascending order by default.
 If you want to sort the records in a descending order, you can use the DESC
keyword.
Syntax
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
Example
1. Select * from Stud order by rno desc;
2. Select * from Stud order by rno ;
3. Select * from Stud order by Name;
4. select name ,city from stud where grade>70 order by name asc, city
desc;
DISTINCT Operator
 The DISTINCT keyword can be used to return only
distinct (different) values.
Syntax
 SELECT DISTINCT column_name(s) FROM 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
certain column
Min
 Used to find the maximum value of a
certain column
Max
 Used to calculate the average value of
the numeric type
Sum
 Used to calculate the sum of all
selected columns
Avg
 Used to Count the number of rows in a
database table
Count
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 of all other functions are similar.
Count()- Syntax
 COUNT function is used to Count the number of rows in a
database table. It can work on both numeric and non-numeric
data types.
Syntax
SELECT COUNT( column_name) FROM table_name;
 COUNT function uses the COUNT(*) that returns the count of all
the rows in a specified table. COUNT(*) considers duplicate
and Null.
Syntax
SELECT COUNT(*) FROM table_name;
Group By and Having Clause
 The MYSQL GROUP BY Clause is used to collect data from
multiple records and group the result by one or more column. It
is generally used in a SELECT statement.
 You can also use some aggregate functions like COUNT, SUM,
MIN, MAX, AVG etc. on the grouped column.
Syntax:
SELECT Column1, column2, ... Column_n,
aggregate_function (expression)
FROM tables
[WHERE conditions]
GROUP BY column1, column2, ... Column_n;
遺看稼岳
Example:
1. SELECT city, COUNT(*) FROM stud
GROUP BY city;
2. SELECT ename, did, SUM(salary) AS "Total dept
salary" FROM emp GROUP BY did;
HAVING Clause
 MySQL Having Clause is used only with GROUP BY
clause.
 It always returns the rows where condition is TRUE.
Syntax:
SELECT column_name(s) FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition ;
GROUP BY & Having Clause- Example
id name type price
123451 Park's Great Hits Music 19
123452 Silly Puddy Toy 5
123453 Playstation Toy 89
123454 Men's T-Shirt Clothing 32
123455 Blouse Clothing 34
123456 Electronica 2002 Music 3
SELECT type, MIN(price) FROM
products GROUP BY type
Type Min(Prize)
Music 3
Toy 5
Clothing 32
Products Table
Out Put
SELECT type, Min(price) FROM
products GROUP BY type
having Min(price)>4
Type Min(Prize)
Toy 5
Clothing 32
遺看稼岳
Example:
SELECT ename, did, SUM(salary) AS "Total dept
salary" FROM emp GROUP BY did having
sum(salary)>50000;
MySQL first function
 The MySQL first function is used to return the first
value of the selected column. Here, we use limit clause
to select first record or more.
Syntax:
SELECT column_name
FROM table_name
LIMIT 1;
SET Operations: Union
 MySQL UNION operator allows you to combine two or more result sets of queries
into a single result set.
Syntax:
SELECT column_list
UNION [DISTINCT | ALL]
SELECT column_list
UNION [DISTINCT | ALL]
SELECT column_list ...
To combine result set of two or more queries using the UNION operator, there are the
basic rules that you must follow:
 First, the number and the orders of columns that appear in all SELECT statements must
be the same.
 Second, the data types of columns must be the same or convertible.
 By default, the UNION operator removes duplicate rows even if you dont specify the
DISTINCT operator explicitly.
遺看稼岳
Union ALL
遺看稼岳
遺看稼岳
Minus Operator
遺看稼岳
Intersect Operator
Intersect Operator
遺看稼岳
Assignment
Eid EName Address Salary Commision
1 Amit Pune 35000 5000
2 Sneha Pune 25000
3 Savita Nasik 28000 2000
4 Pooja Mumbai 19000
5 Sagar Mumbai 25000 3000
1. Find different locations from where employees belong to?
2. What is maximum and minimum salary?
3. Display the content of employee table according to the ascending order of salary amount.
4. Find the name of employee who lived in Nasik or Pune city.
5. Find the name of employees who does not get commission.
6. Change the city of Amit to Nashik.
7. Find the information of employees whose name starts with A.
8. Find the count of staff from Mumbai.
9. Find the count of staff from each city
10.Find the address from where employees are belonging as well as where projects are going on.
11.Find city wise minimum salary.
12.Find city wise maximum salary having maximum salary greater than 26000
13.Delete the employee who is having salary greater than 30,000.
Create Employee table, Project table and add rows shown below
PrNo Addr
10 Mumbai
20 Pune
30 Jalgoan

More Related Content

Similar to SQL Data Manipulation language and DQL commands (20)

ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
ArjayBalberan1
0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf
0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf
0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf
sahilurrahemankhan
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
Swapnali Pawar
My SQL.pptx
My SQL.pptxMy SQL.pptx
My SQL.pptx
KieveBarreto1
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
Vidyasagar Mundroy
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
Dr. C.V. Suresh Babu
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
Sql queries
Sql queriesSql queries
Sql queries
Paritosh Gupta
MySQL-commands.pdf
MySQL-commands.pdfMySQL-commands.pdf
MySQL-commands.pdf
ssuserc5aa74
Oracle
OracleOracle
Oracle
Rajeev Uppala
Sql functions
Sql functionsSql functions
Sql functions
G C Reddy Technologies
Sql
SqlSql
Sql
Aman Lalpuria
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
Mysql1
Mysql1Mysql1
Mysql1
rajikaa
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
Chhom Karath
Commands
CommandsCommands
Commands
Ayushi Goyal
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
newrforce
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
爐爐爐逗し爛爐 爐謹ぐ爛爐爐

More from sonali sonavane (9)

Python chart plotting using Matplotlib.pptx
Python chart plotting using Matplotlib.pptxPython chart plotting using Matplotlib.pptx
Python chart plotting using Matplotlib.pptx
sonali sonavane
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
Random Normal distribution using python programming
Random Normal distribution using python programmingRandom Normal distribution using python programming
Random Normal distribution using python programming
sonali sonavane
program to create bell curve of a random normal distribution
program to create bell curve of a random normal distributionprogram to create bell curve of a random normal distribution
program to create bell curve of a random normal distribution
sonali sonavane
Data Preprocessing: One Hot Encoding Method
Data Preprocessing: One Hot Encoding MethodData Preprocessing: One Hot Encoding Method
Data Preprocessing: One Hot Encoding Method
sonali sonavane
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
Data Preprocessing:Feature scaling methods
Data Preprocessing:Feature scaling methodsData Preprocessing:Feature scaling methods
Data Preprocessing:Feature scaling methods
sonali sonavane
Data Preprocessing:Perform categorization of data
Data Preprocessing:Perform categorization of dataData Preprocessing:Perform categorization of data
Data Preprocessing:Perform categorization of data
sonali sonavane
NBA Subject Presentation08 march 24_A Y 2023-24.pptx
NBA Subject Presentation08 march 24_A Y 2023-24.pptxNBA Subject Presentation08 march 24_A Y 2023-24.pptx
NBA Subject Presentation08 march 24_A Y 2023-24.pptx
sonali sonavane
Python chart plotting using Matplotlib.pptx
Python chart plotting using Matplotlib.pptxPython chart plotting using Matplotlib.pptx
Python chart plotting using Matplotlib.pptx
sonali sonavane
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
Random Normal distribution using python programming
Random Normal distribution using python programmingRandom Normal distribution using python programming
Random Normal distribution using python programming
sonali sonavane
program to create bell curve of a random normal distribution
program to create bell curve of a random normal distributionprogram to create bell curve of a random normal distribution
program to create bell curve of a random normal distribution
sonali sonavane
Data Preprocessing: One Hot Encoding Method
Data Preprocessing: One Hot Encoding MethodData Preprocessing: One Hot Encoding Method
Data Preprocessing: One Hot Encoding Method
sonali sonavane
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
Data Preprocessing:Feature scaling methods
Data Preprocessing:Feature scaling methodsData Preprocessing:Feature scaling methods
Data Preprocessing:Feature scaling methods
sonali sonavane
Data Preprocessing:Perform categorization of data
Data Preprocessing:Perform categorization of dataData Preprocessing:Perform categorization of data
Data Preprocessing:Perform categorization of data
sonali sonavane
NBA Subject Presentation08 march 24_A Y 2023-24.pptx
NBA Subject Presentation08 march 24_A Y 2023-24.pptxNBA Subject Presentation08 march 24_A Y 2023-24.pptx
NBA Subject Presentation08 march 24_A Y 2023-24.pptx
sonali sonavane

Recently uploaded (20)

Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
Production Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptxProduction Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptx
VirajPasare
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Ignacio J. J. Palma Carazo
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptxUHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
ariomthermal2031
Designing of full bridge LLC Resonant converter
Designing of full bridge LLC Resonant converterDesigning of full bridge LLC Resonant converter
Designing of full bridge LLC Resonant converter
NITISHKUMAR143199
DISASTER MANAGEMENT Module1 Notes .pptx
DISASTER MANAGEMENT Module1 Notes  .pptxDISASTER MANAGEMENT Module1 Notes  .pptx
DISASTER MANAGEMENT Module1 Notes .pptx
chandanml7070
Project Manager | Integrated Design Expert
Project Manager | Integrated Design ExpertProject Manager | Integrated Design Expert
Project Manager | Integrated Design Expert
BARBARA BIANCO
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Why the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful ProjectsWhy the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful Projects
Maadhu Creatives-Model Making Company
Unit-03 Cams and Followers in Mechanisms of Machines.pptx
Unit-03 Cams and Followers in Mechanisms of Machines.pptxUnit-03 Cams and Followers in Mechanisms of Machines.pptx
Unit-03 Cams and Followers in Mechanisms of Machines.pptx
Kirankumar Jagtap
Hackathon-Problem-Statements-Technology-Track-with-Link.pptx
Hackathon-Problem-Statements-Technology-Track-with-Link.pptxHackathon-Problem-Statements-Technology-Track-with-Link.pptx
Hackathon-Problem-Statements-Technology-Track-with-Link.pptx
datahiverecruitment
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHMSIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
VLSICS Design
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal buildingAirport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Priyanka Dange
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptxUHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
ariomthermal2031
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
Production Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptxProduction Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptx
VirajPasare
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Ignacio J. J. Palma Carazo
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptxUHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
ariomthermal2031
Designing of full bridge LLC Resonant converter
Designing of full bridge LLC Resonant converterDesigning of full bridge LLC Resonant converter
Designing of full bridge LLC Resonant converter
NITISHKUMAR143199
DISASTER MANAGEMENT Module1 Notes .pptx
DISASTER MANAGEMENT Module1 Notes  .pptxDISASTER MANAGEMENT Module1 Notes  .pptx
DISASTER MANAGEMENT Module1 Notes .pptx
chandanml7070
Project Manager | Integrated Design Expert
Project Manager | Integrated Design ExpertProject Manager | Integrated Design Expert
Project Manager | Integrated Design Expert
BARBARA BIANCO
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Unit-03 Cams and Followers in Mechanisms of Machines.pptx
Unit-03 Cams and Followers in Mechanisms of Machines.pptxUnit-03 Cams and Followers in Mechanisms of Machines.pptx
Unit-03 Cams and Followers in Mechanisms of Machines.pptx
Kirankumar Jagtap
Hackathon-Problem-Statements-Technology-Track-with-Link.pptx
Hackathon-Problem-Statements-Technology-Track-with-Link.pptxHackathon-Problem-Statements-Technology-Track-with-Link.pptx
Hackathon-Problem-Statements-Technology-Track-with-Link.pptx
datahiverecruitment
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHMSIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHM
VLSICS Design
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal buildingAirport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Priyanka Dange
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptxUHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
UHV unit-2UNIT - II HARMONY IN THE HUMAN BEING.pptx
ariomthermal2031

SQL Data Manipulation language and DQL commands

  • 1. DML COMMANDS BY Ms. Sonali Sonavane
  • 2. INSERT Command MySQL INSERT statement is used to store or add data in MySQL table within the database. We can perform insertion of records in two ways using a single query in MySQL: Insert record in a single row Insert record in multiple rows Syntax: INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN ); Example: INSERT INTO People (id, name, occupation, age) VALUES (101, 'Peter', 'Engineer', 32);
  • 3. 遺看稼岳 Inserting Multiple records into table Syntax: INSERT INTO table_name VALUES ( value1, value2,...valueN ),( value1, value2,...valueN ), ...........,(value1, value2,...valueN ); Example: INSERT INTO People VALUES (102, 'Joseph', 'Develope r', 30),(103, 'Mike', 'Leader', 28), (104, 'Stephen', 'Scientist', 45);
  • 4. 遺看稼岳 If we want to store records without giving all fields, we use the following partial field statements. In such case, it is mandatory to specify field names. Example: INSERT INTO People (name, occupation) VALUES ('Stephen', 'Scientist'), ('Bob', 'Actor');
  • 5. Update command MySQL UPDATE query is a DML statement used to modify the data of the MySQL table within the database. The UPDATE statement is used with the SET and WHERE clauses. The SET clause is used to change the values of the specified column. We can update single or multiple columns at a time.
  • 6. 遺看稼岳 Syntax: UPDATE table_name SET column_name1 = new - value1,column_name2=new-value2, ... [WHERE Clause] Example: 1. update stud set city='pune' where name='aarti'; (Only city field of row having name as aarti will be changed as pune) 2. . update stud set city='pune' (city field of All row will be changed as Pune)
  • 7. DELETE Command MySQL DELETE statement is used to delete data from the MySQL table within the database. By using delete statement, we can delete records on the basis of conditions. Syntax: DELETE FROM table_name WHERE (Condition specified); Example: delete from stud where grade='72'; DELETE FROM Stud;
  • 8. DQL Commands:SELECT The MySQL SELECT statement is used to fetch data from the one or more tables in MySQL. We can retrieve records of all fields or specified fields. Syntax: SELECT column list FROM table [WHERE conditions]; Example: 1. Select rno, name from stud; 2. Select * from stud; 3. Select * from stud where grade>60; 4. Select grade from Stud where name=aarti;
  • 9. Where clause MySQL WHERE Clause is used with SELECT, INSERT, UPDATE and DELETE clause to filter the results. It specifies a specific position where you have to do 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);
  • 10. 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
  • 11. LIKE Operator- Example P_Id LastName Address 1 Heena Pune 2 Savita Pune 3 Sarika Bombay "Persons" table We use the following SELECT statement: 1. SELECT LastName from Person where LastName like S% 2.SELECT ename FROM emp WHERE address LIKE _________90'; 3. SELECT ename FROM emp WHERE ecity NOT LIKE mum%';
  • 12. Order By- clause The ORDER BY keyword is used to sort the result-set by a specified column. The ORDER BY keyword sort the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword. Syntax SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC Example 1. Select * from Stud order by rno desc; 2. Select * from Stud order by rno ; 3. Select * from Stud order by Name; 4. select name ,city from stud where grade>70 order by name asc, city desc;
  • 13. DISTINCT Operator The DISTINCT keyword can be used to return only distinct (different) values. Syntax SELECT DISTINCT column_name(s) FROM table_name; Example SELECT distinct(Address) from emp;
  • 14. 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');
  • 15. 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;
  • 16. 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";
  • 17. 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;
  • 18. 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 certain column Min Used to find the maximum value of a certain column Max Used to calculate the average value of the numeric type Sum Used to calculate the sum of all selected columns Avg Used to Count the number of rows in a database table Count
  • 19. 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 of all other functions are similar.
  • 20. Count()- Syntax COUNT function is used to Count the number of rows in a database table. It can work on both numeric and non-numeric data types. Syntax SELECT COUNT( column_name) FROM table_name; COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table. COUNT(*) considers duplicate and Null. Syntax SELECT COUNT(*) FROM table_name;
  • 21. Group By and Having Clause The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one or more column. It is generally used in a SELECT statement. You can also use some aggregate functions like COUNT, SUM, MIN, MAX, AVG etc. on the grouped column. Syntax: SELECT Column1, column2, ... Column_n, aggregate_function (expression) FROM tables [WHERE conditions] GROUP BY column1, column2, ... Column_n;
  • 22. 遺看稼岳 Example: 1. SELECT city, COUNT(*) FROM stud GROUP BY city; 2. SELECT ename, did, SUM(salary) AS "Total dept salary" FROM emp GROUP BY did;
  • 23. HAVING Clause MySQL Having Clause is used only with GROUP BY clause. It always returns the rows where condition is TRUE. Syntax: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ;
  • 24. GROUP BY & Having Clause- Example id name type price 123451 Park's Great Hits Music 19 123452 Silly Puddy Toy 5 123453 Playstation Toy 89 123454 Men's T-Shirt Clothing 32 123455 Blouse Clothing 34 123456 Electronica 2002 Music 3 SELECT type, MIN(price) FROM products GROUP BY type Type Min(Prize) Music 3 Toy 5 Clothing 32 Products Table Out Put SELECT type, Min(price) FROM products GROUP BY type having Min(price)>4 Type Min(Prize) Toy 5 Clothing 32
  • 25. 遺看稼岳 Example: SELECT ename, did, SUM(salary) AS "Total dept salary" FROM emp GROUP BY did having sum(salary)>50000;
  • 26. MySQL first function The MySQL first function is used to return the first value of the selected column. Here, we use limit clause to select first record or more. Syntax: SELECT column_name FROM table_name LIMIT 1;
  • 27. SET Operations: Union MySQL UNION operator allows you to combine two or more result sets of queries into a single result set. Syntax: SELECT column_list UNION [DISTINCT | ALL] SELECT column_list UNION [DISTINCT | ALL] SELECT column_list ... To combine result set of two or more queries using the UNION operator, there are the basic rules that you must follow: First, the number and the orders of columns that appear in all SELECT statements must be the same. Second, the data types of columns must be the same or convertible. By default, the UNION operator removes duplicate rows even if you dont specify the DISTINCT operator explicitly.
  • 37. Assignment Eid EName Address Salary Commision 1 Amit Pune 35000 5000 2 Sneha Pune 25000 3 Savita Nasik 28000 2000 4 Pooja Mumbai 19000 5 Sagar Mumbai 25000 3000 1. Find different locations from where employees belong to? 2. What is maximum and minimum salary? 3. Display the content of employee table according to the ascending order of salary amount. 4. Find the name of employee who lived in Nasik or Pune city. 5. Find the name of employees who does not get commission. 6. Change the city of Amit to Nashik. 7. Find the information of employees whose name starts with A. 8. Find the count of staff from Mumbai. 9. Find the count of staff from each city 10.Find the address from where employees are belonging as well as where projects are going on. 11.Find city wise minimum salary. 12.Find city wise maximum salary having maximum salary greater than 26000 13.Delete the employee who is having salary greater than 30,000. Create Employee table, Project table and add rows shown below PrNo Addr 10 Mumbai 20 Pune 30 Jalgoan