SlideShare a Scribd company logo
1 of 35
Yasir musthafa pp
yasirmusthafapp@gmail.com
www.facebook.com/yasirmusthafa
twitter.com/yasirmusthafapp
in.linkedin.com/in/yasirmusthafapp
8891396749
Sql statements ,functions and joins
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
Sql statements
• Query or command to perform a task in a
database
3 type
1. DDL
2. DML
3. DCL
DDL
Data definition language
• Create
• Alter
• Drop
• truncate
Create
Syntax in mysql
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
....
);Example
create table tbl_stock
(
pk_int_stock_id int auto_increment,
vchr_name varchar(20),
int_quantity int,
int_price int,
primary key(pk_int_stock_id)
);
Alter
Syntax in mysql
Alter table table_name modify column
column_name data_type;
Example
alter table tbl_stock modify column int_price
float;
Drop
Syntax in mysql
Drop table table_name;
Example
Drop table tbl_student;
Truncate
Syntax in mysql
Truncate table table_name;
Example
Truncate table tbl_student;
DML
Data manipulation language
• Select
• Insert
• Update
• delete
Select
Syntax in mysql
Select * from table_name;
Example
Select * from tbl_stock;
Insert
Syntax in mysql
insert into table_name values
( );
Example
insert into tbl_stock values
(NULL,"mouse",10,500,1);
Update
Syntax in mysql
Update table_name set column_name=
Example
• update tbl_stock set int_price=int_price+1.50;
delete
Syntax in mysql
Delete from table_name;
Example
Delete from tbl_stock;
Difference between delete and truncate??
DCL
Data control language
• Grant
• Revoke
• Commit
• rollback
Grant
Syntax in mysql
GRANT privilege_type ON table_name TO
‘user_name'@'localhost';
Example
GRANT select ON tbl_supplier TO
'john'@'localhost';
Revoke
Syntax in mysql
REVOKE privilege_type ON table_name FROM
‘user_name'@'localhost';
Example
REVOKE select ON tbl_supplier FROM
'suhail'@'localhost';
functions
• Built in function-perform calculation on data
1. Aggregate function
2. Scalar function
Aggregate function
• Return a single value for all the values in the
column after calculation
AVG()
Mysql syntax
Select avg(coulmn_name) from table_name;
Example
Select avg(int_salary) from employee;
COUNT(),FIRST(),LAST(),MAX(),MIN(),SUM()
Group by
• To group the result set by one or more column
• Often used in conjunction with aggregate
function
Syntax in mysql
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
Example
Select vchr_city,sum(mark) from tbl_student group by vchr_city;
Scalar function
• Return single value for each value in a column
UCASE()
Syntax in mysql
Select UCASE (column_name) from table_name;
Example
Select UCASE(first_name) from tbl_student;
• LCASE(),MID(),LEN(),ROUND(),NOW(),FORMAT()
Joins
• Used to combine rows from two or more
tables
Different joins
• inner join
• Left join
• Right join
Inner join
• Returns all rows when there is at least one
match in BOTH tables
Syntax in mysql
Select column_name(s) from table1 join table2 on
table1.column_name=table2.column_name;
Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
pk_int_class_id Vchr_class_name int_dept_id
1 CS100 1
2 CC300 5
3 EC100 2
4 MECH100 4
Example
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept join tbl_classes on tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
The result set will be
Vchr_department_
name
Vchr_class_name Pk_int_dept_id int_dept_id
CS CS100 1 1
EC EC100 2 2
MECH MECH100 4 4
Left join
• returns all rows from the left table (table1), with the matching
rows in the right table (table2).
• Syntax in mysql
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
Pk_int_class_id Vchr_class_name int_dept_id
1 CS100 1
2 EC100 2
3 CC100 5
4 MECH100 4
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept LEFT join tbl_classes on
tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
The result will be
Vchr_dept_na
me
Vchr_class_na
me
Pk_int_dept_i
d
int_dept_id
CS CS100 1 1
EC EC100 2 2
EE NULL 3 NULL
MECH MECH100 4 4
Right join
• Return all rows from the right table, and the matched rows from the left
table
Syntax in mysql
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
Pk_int_class_id Vchr_class_name int_dept_name
1 CS100 1
2 EC100 2
4 MECH100 4
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept RIGHT join tbl_classes on
tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
The result will be
Vchr_dept_na
me
Vchr_class_na
me
Pk_int_dept_i
d
int_dept_id
CS CS100 1 1
EC EC100 2 2
MECH MECH100 4 4
NULL CC100 NULL 5
Thank you
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

More Related Content

What's hot (20)

Day 1b R structures objects.pptx
Day 1b   R structures   objects.pptxDay 1b   R structures   objects.pptx
Day 1b R structures objects.pptx
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
Day 5b statistical functions.pptx
Day 5b   statistical functions.pptxDay 5b   statistical functions.pptx
Day 5b statistical functions.pptx
 
SQL Pattern Matching – should I start using it?
SQL Pattern Matching – should I start using it?SQL Pattern Matching – should I start using it?
SQL Pattern Matching – should I start using it?
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Ddl & dml commands
Ddl & dml commandsDdl & dml commands
Ddl & dml commands
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
 
Data Fragementation
Data FragementationData Fragementation
Data Fragementation
 
JCL UTILITIES IEBCOPY
JCL UTILITIES IEBCOPYJCL UTILITIES IEBCOPY
JCL UTILITIES IEBCOPY
 
Intro to tsql unit 3
Intro to tsql   unit 3Intro to tsql   unit 3
Intro to tsql unit 3
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle Basic
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
SQL Queries - DML Commands
SQL Queries - DML CommandsSQL Queries - DML Commands
SQL Queries - DML Commands
 
2
22
2
 
Normalization case
Normalization caseNormalization case
Normalization case
 

Similar to Sql statement,functions and joins (20)

Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql
SqlSql
Sql
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Sql
SqlSql
Sql
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
 
Mysql1
Mysql1Mysql1
Mysql1
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
Mysql
MysqlMysql
Mysql
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Most useful queries
Most useful queriesMost useful queries
Most useful queries
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
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
 
SQL
SQLSQL
SQL
 
SQL
SQL SQL
SQL
 
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
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Sql statement,functions and joins

  • 1.
  • 3. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. Sql statements • Query or command to perform a task in a database 3 type 1. DDL 2. DML 3. DCL
  • 5. DDL Data definition language • Create • Alter • Drop • truncate
  • 6. Create Syntax in mysql CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), .... );Example create table tbl_stock ( pk_int_stock_id int auto_increment, vchr_name varchar(20), int_quantity int, int_price int, primary key(pk_int_stock_id) );
  • 7. Alter Syntax in mysql Alter table table_name modify column column_name data_type; Example alter table tbl_stock modify column int_price float;
  • 8. Drop Syntax in mysql Drop table table_name; Example Drop table tbl_student;
  • 9. Truncate Syntax in mysql Truncate table table_name; Example Truncate table tbl_student;
  • 10. DML Data manipulation language • Select • Insert • Update • delete
  • 11. Select Syntax in mysql Select * from table_name; Example Select * from tbl_stock;
  • 12. Insert Syntax in mysql insert into table_name values ( ); Example insert into tbl_stock values (NULL,"mouse",10,500,1);
  • 13. Update Syntax in mysql Update table_name set column_name= Example • update tbl_stock set int_price=int_price+1.50;
  • 14. delete Syntax in mysql Delete from table_name; Example Delete from tbl_stock; Difference between delete and truncate??
  • 15. DCL Data control language • Grant • Revoke • Commit • rollback
  • 16. Grant Syntax in mysql GRANT privilege_type ON table_name TO ‘user_name'@'localhost'; Example GRANT select ON tbl_supplier TO 'john'@'localhost';
  • 17. Revoke Syntax in mysql REVOKE privilege_type ON table_name FROM ‘user_name'@'localhost'; Example REVOKE select ON tbl_supplier FROM 'suhail'@'localhost';
  • 18. functions • Built in function-perform calculation on data 1. Aggregate function 2. Scalar function
  • 19. Aggregate function • Return a single value for all the values in the column after calculation AVG() Mysql syntax Select avg(coulmn_name) from table_name; Example Select avg(int_salary) from employee; COUNT(),FIRST(),LAST(),MAX(),MIN(),SUM()
  • 20. Group by • To group the result set by one or more column • Often used in conjunction with aggregate function Syntax in mysql SELECT column_name, aggregate_function(column_name) FROM table_name GROUP BY column_name; Example Select vchr_city,sum(mark) from tbl_student group by vchr_city;
  • 21. Scalar function • Return single value for each value in a column UCASE() Syntax in mysql Select UCASE (column_name) from table_name; Example Select UCASE(first_name) from tbl_student; • LCASE(),MID(),LEN(),ROUND(),NOW(),FORMAT()
  • 22. Joins • Used to combine rows from two or more tables Different joins • inner join • Left join • Right join
  • 23. Inner join • Returns all rows when there is at least one match in BOTH tables Syntax in mysql Select column_name(s) from table1 join table2 on table1.column_name=table2.column_name;
  • 24. Pk_int_dept_id Vchr_dept_name 1 CS 2 EC 3 EE 4 MECH pk_int_class_id Vchr_class_name int_dept_id 1 CS100 1 2 CC300 5 3 EC100 2 4 MECH100 4 Example select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from tbl_dept join tbl_classes on tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
  • 25. The result set will be Vchr_department_ name Vchr_class_name Pk_int_dept_id int_dept_id CS CS100 1 1 EC EC100 2 2 MECH MECH100 4 4
  • 26. Left join • returns all rows from the left table (table1), with the matching rows in the right table (table2). • Syntax in mysql SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name;
  • 27. Pk_int_dept_id Vchr_dept_name 1 CS 2 EC 3 EE 4 MECH Pk_int_class_id Vchr_class_name int_dept_id 1 CS100 1 2 EC100 2 3 CC100 5 4 MECH100 4 select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from tbl_dept LEFT join tbl_classes on tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
  • 28. The result will be Vchr_dept_na me Vchr_class_na me Pk_int_dept_i d int_dept_id CS CS100 1 1 EC EC100 2 2 EE NULL 3 NULL MECH MECH100 4 4
  • 29. Right join • Return all rows from the right table, and the matched rows from the left table Syntax in mysql SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name;
  • 30. Pk_int_dept_id Vchr_dept_name 1 CS 2 EC 3 EE 4 MECH Pk_int_class_id Vchr_class_name int_dept_name 1 CS100 1 2 EC100 2 4 MECH100 4 select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from tbl_dept RIGHT join tbl_classes on tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
  • 31. The result will be Vchr_dept_na me Vchr_class_na me Pk_int_dept_i d int_dept_id CS CS100 1 1 EC EC100 2 2 MECH MECH100 4 4 NULL CC100 NULL 5
  • 33. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 34. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 35. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us