SlideShare una empresa de Scribd logo
1 de 10
SQL (Structured Query Language)
SQL Queries:
• SQL is a standard computer language for accessing and manipulating database.
• SQL statement are used to retrieve and update data in a database.
Types of Language;
There are 4 types of language
1. Data Definition Language.
2. Data Manipulation Language.
3. Transaction Control Language.
4. Data Control Language.
1. DATA DEFINITION LANGUAGE:
The Data Definition Language (DDL) permits database
Tables to be created or deleted.
• CREATE DATABASE- creates a new database table
CREAT DATABASE Cricket
CREAT A TABLE:
CREAT TABLE cricket (sarov varchar (20), six int, four int, two int, out int)
• ALTER TABLE - alters a database table
ADD COLUMN:
ALTER TABLE cricket ADD hundreds int
DROP COLUMN:
ALTER TABLE cricket DROP column hundreds
• DROP TABLE - deletes a database table
DROP cricket
2. Data Manipulation Language:
DML is used for executing queries.
• SELECT - extracts data from a database table
To select any two columns:
SELECT India, gold FROM sundar
To select all columns:
SELECT * FROM sundar
• UPDATE – It is used to modify the data in a table.
UPDATE Sundar SET name=’north’ where India=’ravi’
4Update one column in a row:
UPDATE sundar SET name =’sarov’ WHERE name=’priya’
Update several Columns in a row:
UPDATE sundar SET gold=’55’, name = ‘99’ WHERE name=’priya’
• DELETE - deletes data from a database table.
DELETE FROM sundar Where India=’abi’
Delete a Row:
DELETE FROM sundar where name=’rajesh’
Delete all Row:
DELETE FROM sundar
• INSERT INTO - inserts new data into a database table
INSET INTO sundar values (‘rajesh’,’50’,’55’,’60’,’6’)
INSERT DATA IN A SPECIFIED COLUMN:
INSERT INTO sundar (name, four) values (‘priya’, ‘20’)
To select the maximum value:
select max(two)from cricket
To Select the 2nd
maximum Value:
select max(two)from cricket where two<(select max(two) from cricket)
To Select the 5th
maximum value:
select max(six)from cricket as x where 5=(select count(distinct
six)from cricket where six>=x.six)
Select max(column2) FROM table1 AS X where N=(SELECT COUNT (DISTINCT
Column2) FROM table1 where column2>=X.column2)
To select the minimum value:
select min (six)from cricket
To Select the 2nd
minimum value:
select min(six)from cricket where SIX >(select min(six)from cricket)
JOINS:
Joins are to retrive data from two or more tables.
JOIN Refering of two tables:
Select table1.anycolumn,table2.anycolumn from table1,table2 where
table1.samecolumn=table2.samecolumn
select sarov.descripition,janika.company from sarov,janika where
sarov.descripition=janika.descripition
Inner joint
The intersection values of the two application.
Select field1.column1, field2.column2 from table1 INNER JOIN table2 ON
table1.samevalue=table2.samevalue.
Select oviya.serial, oviya1.Mgf from oviya inner join oviya1 on
oviya.company=oviya1.company
Left join:
Left join means display all the rows in table1 even there is no match in
table2.
select oviya.serial,oviya1.Mgf from oviya left join oviya1 on
oviya.company=oviya1.company
Right join:
Right join means display all the rows in table2 even there is no match in
table1.
select oviya.serial,oviya1.mgf from oviya right join oviya1 on
oviya.company=oviya1.company
Union :
(display the same name in one time)Union command is used to display
common columns in table1 & table2,when using union all column should be same
data.
Select company from oviya UNION select company from oviya1
Union ALL:
(display the same name twice)Union All is used to display all the same
column name
select company from oviya UNION ALL select company from oviya1
Order by:
Order by command is used to display in alphabetic order .
select company,model from oviya ORDER by company
Group by:
To find the sum of each and every rows(if two row’s have same name but
the amount is varies it addes that two amount values in one name and)
Select column1,sum(column2)from table1 group by column2
select company,sum(sum)from oviya2 group by sum
Having:
If the column is aggregate function we use having.
(i.e. we can also use where if it is not aggregate function)
Select column1, sum (summing column) from table1 group by column1
having Sum (summing column) condition value.
Where:
It is used to select particular value, if it is conditional.
select oviya.serial,oviya1.Num from oviya,oviya1 where
oviya.company=oviya1.company
ALIAS:
Changing the column name or table name
Column name alias:
Which is used to change the column name only
Select column1 as newcolumn1, column2 as newcolumn2 from
table1
Table name alias:
Which is used to change the table name only
Select column1, column2 from table1 AS newtable1
Between(AND):
It is used to select inbetween data’s only.
Select*from table1 where column1 between ’first name’ and ‘Last name’
Between (NOT):
Select*from table1 where coolumn1 NOT Between ‘first name’ and ‘last name’
AND:
It is used to display a row even if we give any two columns with particular row
select*from cool where SI='3'and Price='14'
OR :
It is used to display both the items with same name,it
is enough to give one command.
select*from cool where Items='mirinda' or Price='10'
SELECT *FROM table1 where column1=’value’ or column2=’value’
AND & OR:
Joins two or more conditions in a WHERE clause
Select column1,column2,column3 FROM table WHERE column1=value1 AND
column3= value2 OR column3= value2
Select country, mobile, status from food where country='India' and
Status='good' or status='bad'
OR
Select* from food where mobile='1100' or mobile='2200' and country='India'
IN:
To find the particular two details in the row is called IN
Select*from oviya2 where position in('test','j test')
Select *from table1 where column1 in (firstname, lastname)
Function:
It is the aggregate function for calculation and counting.
* Function can return value
* We can pass arguments to the function
Select function (column) from table.
Two types of Function
1. AGGREGATE FUNCTION:
Operate against the collection of values but returns single value.
2. SCALAR FUNCTION:
Operate against the collection of single values but returns single value.
STRUCTURE:
• Structure can not return value
• We can not pass any argument to the structure.
DIFFERENCE B/W HAVING & WHERE:
HAVING WHERE
HAVING is used only in Aggregate function Where is not used in the Aggregate function
SELECT INTO:
It is used to take backup from the previous table
select SI,Items,Price,Quantity into oviya5 from cool
Select column1, column2, column3 into new table from table1
TO DISPLAY ALL THE COLUMN ONCE MORE
Select column1, column2, column3, table1.* from table1
30 08 Final Sql

Más contenido relacionado

La actualidad más candente

Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
Syed Zaid Irshad
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
Java class 8
Java class 8Java class 8
Java class 8
Edureka!
 

La actualidad más candente (19)

MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Spufi
SpufiSpufi
Spufi
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
Sql select
Sql select Sql select
Sql select
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
SQL
SQLSQL
SQL
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL report
SQL reportSQL report
SQL report
 
Java class 8
Java class 8Java class 8
Java class 8
 

Similar a 30 08 Final Sql

Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 

Similar a 30 08 Final Sql (20)

Commands
CommandsCommands
Commands
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
dbms.pdf
dbms.pdfdbms.pdf
dbms.pdf
 
Bootcamp sql fundamental
Bootcamp sql fundamentalBootcamp sql fundamental
Bootcamp sql fundamental
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 
MY SQL
MY SQLMY SQL
MY SQL
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
SQL
SQLSQL
SQL
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
1670595076250.pdf
1670595076250.pdf1670595076250.pdf
1670595076250.pdf
 
Cheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understandingCheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understanding
 
SQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdfSQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdf
 
SQL learning notes and all code.pdf
SQL learning notes and all code.pdfSQL learning notes and all code.pdf
SQL learning notes and all code.pdf
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
SQL Class Note By Amit Maity PowerPoint Presentation
SQL Class Note By Amit Maity PowerPoint PresentationSQL Class Note By Amit Maity PowerPoint Presentation
SQL Class Note By Amit Maity PowerPoint Presentation
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

30 08 Final Sql

  • 1. SQL (Structured Query Language) SQL Queries: • SQL is a standard computer language for accessing and manipulating database. • SQL statement are used to retrieve and update data in a database. Types of Language; There are 4 types of language 1. Data Definition Language. 2. Data Manipulation Language. 3. Transaction Control Language. 4. Data Control Language. 1. DATA DEFINITION LANGUAGE: The Data Definition Language (DDL) permits database Tables to be created or deleted. • CREATE DATABASE- creates a new database table CREAT DATABASE Cricket
  • 2. CREAT A TABLE: CREAT TABLE cricket (sarov varchar (20), six int, four int, two int, out int) • ALTER TABLE - alters a database table ADD COLUMN: ALTER TABLE cricket ADD hundreds int DROP COLUMN: ALTER TABLE cricket DROP column hundreds • DROP TABLE - deletes a database table DROP cricket 2. Data Manipulation Language: DML is used for executing queries. • SELECT - extracts data from a database table To select any two columns: SELECT India, gold FROM sundar To select all columns: SELECT * FROM sundar
  • 3. • UPDATE – It is used to modify the data in a table. UPDATE Sundar SET name=’north’ where India=’ravi’ 4Update one column in a row: UPDATE sundar SET name =’sarov’ WHERE name=’priya’ Update several Columns in a row: UPDATE sundar SET gold=’55’, name = ‘99’ WHERE name=’priya’ • DELETE - deletes data from a database table. DELETE FROM sundar Where India=’abi’ Delete a Row: DELETE FROM sundar where name=’rajesh’ Delete all Row: DELETE FROM sundar • INSERT INTO - inserts new data into a database table INSET INTO sundar values (‘rajesh’,’50’,’55’,’60’,’6’)
  • 4. INSERT DATA IN A SPECIFIED COLUMN: INSERT INTO sundar (name, four) values (‘priya’, ‘20’) To select the maximum value: select max(two)from cricket To Select the 2nd maximum Value: select max(two)from cricket where two<(select max(two) from cricket) To Select the 5th maximum value: select max(six)from cricket as x where 5=(select count(distinct six)from cricket where six>=x.six) Select max(column2) FROM table1 AS X where N=(SELECT COUNT (DISTINCT Column2) FROM table1 where column2>=X.column2) To select the minimum value: select min (six)from cricket To Select the 2nd minimum value: select min(six)from cricket where SIX >(select min(six)from cricket) JOINS: Joins are to retrive data from two or more tables. JOIN Refering of two tables: Select table1.anycolumn,table2.anycolumn from table1,table2 where table1.samecolumn=table2.samecolumn select sarov.descripition,janika.company from sarov,janika where sarov.descripition=janika.descripition
  • 5. Inner joint The intersection values of the two application. Select field1.column1, field2.column2 from table1 INNER JOIN table2 ON table1.samevalue=table2.samevalue. Select oviya.serial, oviya1.Mgf from oviya inner join oviya1 on oviya.company=oviya1.company Left join: Left join means display all the rows in table1 even there is no match in table2. select oviya.serial,oviya1.Mgf from oviya left join oviya1 on oviya.company=oviya1.company Right join: Right join means display all the rows in table2 even there is no match in table1. select oviya.serial,oviya1.mgf from oviya right join oviya1 on oviya.company=oviya1.company Union : (display the same name in one time)Union command is used to display common columns in table1 & table2,when using union all column should be same data. Select company from oviya UNION select company from oviya1
  • 6. Union ALL: (display the same name twice)Union All is used to display all the same column name select company from oviya UNION ALL select company from oviya1 Order by: Order by command is used to display in alphabetic order . select company,model from oviya ORDER by company Group by: To find the sum of each and every rows(if two row’s have same name but the amount is varies it addes that two amount values in one name and) Select column1,sum(column2)from table1 group by column2 select company,sum(sum)from oviya2 group by sum Having: If the column is aggregate function we use having. (i.e. we can also use where if it is not aggregate function) Select column1, sum (summing column) from table1 group by column1 having Sum (summing column) condition value. Where: It is used to select particular value, if it is conditional. select oviya.serial,oviya1.Num from oviya,oviya1 where oviya.company=oviya1.company ALIAS:
  • 7. Changing the column name or table name Column name alias: Which is used to change the column name only Select column1 as newcolumn1, column2 as newcolumn2 from table1 Table name alias: Which is used to change the table name only Select column1, column2 from table1 AS newtable1 Between(AND): It is used to select inbetween data’s only. Select*from table1 where column1 between ’first name’ and ‘Last name’ Between (NOT): Select*from table1 where coolumn1 NOT Between ‘first name’ and ‘last name’ AND: It is used to display a row even if we give any two columns with particular row select*from cool where SI='3'and Price='14' OR : It is used to display both the items with same name,it is enough to give one command. select*from cool where Items='mirinda' or Price='10' SELECT *FROM table1 where column1=’value’ or column2=’value’
  • 8. AND & OR: Joins two or more conditions in a WHERE clause Select column1,column2,column3 FROM table WHERE column1=value1 AND column3= value2 OR column3= value2 Select country, mobile, status from food where country='India' and Status='good' or status='bad' OR Select* from food where mobile='1100' or mobile='2200' and country='India' IN: To find the particular two details in the row is called IN Select*from oviya2 where position in('test','j test') Select *from table1 where column1 in (firstname, lastname) Function: It is the aggregate function for calculation and counting. * Function can return value * We can pass arguments to the function Select function (column) from table. Two types of Function 1. AGGREGATE FUNCTION: Operate against the collection of values but returns single value. 2. SCALAR FUNCTION: Operate against the collection of single values but returns single value.
  • 9. STRUCTURE: • Structure can not return value • We can not pass any argument to the structure. DIFFERENCE B/W HAVING & WHERE: HAVING WHERE HAVING is used only in Aggregate function Where is not used in the Aggregate function SELECT INTO: It is used to take backup from the previous table select SI,Items,Price,Quantity into oviya5 from cool Select column1, column2, column3 into new table from table1 TO DISPLAY ALL THE COLUMN ONCE MORE Select column1, column2, column3, table1.* from table1