SlideShare a Scribd company logo
1 of 32
ManeeshaK K
maneeshakk16@gmail.com
www.facebook.com/username
twitter.com/username
in.linkedin.com/in/Maneesha
7559813984
SQL
STATEMENTS , FUNCTIONS & 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
A query/command to perform a task in a
database.
CREATE
ALTER Data Definition Language(DDL)
DROP
INSERT
UPDATE Data Manipulation Language (DML)
DELETE
GRANT
REVOKE Data Control Language(DCL)
DDL - Data Definition Language
1. Create
To Create a Database.
Syntax :
create database databasename;
Eg :
create database student;
2. Use
Syntax :
use databasename;
Eg :
use student;
To Create Table
Syntax :
create table <TableName>
(
ColumnName1 Datatype(Size) Constraint ,
ColumnName2 Datatype(Size) Constraint ,
-------------------------------------------------------
);
Eg : create table tbl_student
(
pk_int_roll_no int(4) not null primary key,
vchr_name varchar(20),
char_gender char(2)
);
3. Alter Table
To change the structure of the table.
alter table tbl_student add (int_marks int(2));
alter table tbl_student drop column char_gender;
alter table tbl_student change vchr_name vchr_name
varchar(30);
4. Drop Table
To remove the tables.
Syntax :
drop table tablename;
Eg :
drop table tbl_student;
DML - Data Manipulation Language
1. Insert
To insert rows into a table.
Syntax :
insert into tablename(columnname1,columnname2,…)values(value1,value2,…);
Eg :
insert into tbl_student(pk_int_roll_no,vchr_name,int_marks)values(1,’Anu’,96);
2. Select
To extract data from the database.
(SELECT identifies what columns FROM identifies which table)
Syntax :
select * / [distinct]column_name from table_name where [condition];
Eg :
•select * from tbl_student;
•select pk_int_roll_no,vchr_name from tbl_student;
•select vchr_name from tbl_student where int_marks>80;
3. Update
To change the contents(rows /columns) of the
table.
Syntax :
update tablename set columnname=values
where condition;
Eg :
update tbl_student set int_marks=89 where
pk_int_roll_no=2;
4. Delete
To delete rows from the table.
Syntax :
delete from tablename where [condition];
Eg :
delete from tbl_student where int_marks<40;
DCL - Data Controll Language
1. Grant
Syntax :
grant privilage_type on tablename to
‘user_name'@'localhost';
Eg :
grant all on tbl_student to ‘manu’@’localhost’;
2 . Revoke
Syntax :
revoke privilege_type on table_name from
‘user_name'@'localhost';
Eg :
revoke select on tbl_student from ‘manu'@'localhost';
FUNCTIONS
SQL - Functions
SQL functions are used for performing calculations
on data.
Types of Functions
Aggregate Functions
Scalar Functions
Aggregate Functions
•The functions that can be applied to all rows in table or
to a subset of the table specified by the where clause.
•Functions return single value for a group of rows in the
table.
•Sum()
•Avg()
•Min()
•Max()
•Count()
pk_int_roll_no vchr_name int_marks
1 Anu 96
2 Veena 89
3 Amal 79
4 Reema 92
•select max(int_marks),min(int_marks),avg(int_marks) from
tbl_student;
Max(int_marks) min(int_marks) avg(int_marks)
96 79 81.7
•select count(pk_int_roll_no)as total_students from
tbl_student;
total_students
4
Group By
To group the result set by one or more column.
Often used in conjunction with aggregate function.
Syntax :
Select column_name, aggregate_function(column_name)
from table_name
group by column_name;
Eg :
Select vchr_name,sum(int_marks) from tbl_student group by
vchr_name;
Scalar function
These functions return a single value for each values of a
particular column given as input.
•Lcase()
•Ucase()
•Round()
Eg :
Select ucase(vchr_name) from tbl_student;
Select lcase(vchr_name) from tbl_student;
Select round(int_marks) from tbl_student where
pk_int_roll_no=3;
JOINS
JOINS
To combine rows from two or more tables.
Types of Joins ::
1. Inner join
2. Outer join
a) Left join
b) Right join
INNER JOIN
Returns all rows when there is at least one match in
BOTH tables.
Syntax :
select column_name(s) from table1 join table2 on
table1.column_name=table2.column_name;
select stud_name,dept_name from tbl_student join tbl_dept
where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_dept_id
1 Anu 1
2 Veena 3
3 Abhi 2
4 John 1
dept_id dept_name
1 CS
2 EC
3 QS
stud_name dept_name
Anu CS
Veena QS
Abhi EC
John CS
I
n
n
e
r
j
o
i
n
LEFT OUTER JOIN
Returns all rows from the left table (table1), with
the matching rows in the right table (table2).
Syntax :
select column_name(s)
from table1
left join table2
on table1.column_name=table2.column_name;
select stud_name,dept_name from tbl_student
left join tbl_dept where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_dept_id
1 Anu 1
2 Veena 3
3 Abhi 4
4 John 1
dept_id dept_name
1 CS
2 EC
3 QS
l
e
f
t
j
o
i
n
stud_name dept_name
Anu CS
Veena QS
Abhi NULL
John CS
RIGHT OUTER JOIN
Return all rows from the right table, and the matched
rows from the left table.
Syntax :
select column_name(s)
from table1
right join table2
on table1.column_name=table2.column_name;
select stud_name,dept_name from tbl_student
lright join tbl_dept where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_dept_id
1 Anu 1
2 Veena 3
3 Abhi 4
4 John 1
dept_id dept_name
1 CS
2 EC
3 QS
R
i
g
h
t
j
o
i
n
stud_name dept_name
Anu CS
Veena QS
Abhi NULL
John CS
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)

DML Commands
DML CommandsDML Commands
DML Commands
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
1 ddl
1 ddl1 ddl
1 ddl
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
SQL
SQLSQL
SQL
 
Assignment#05
Assignment#05Assignment#05
Assignment#05
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
Assignment#02
Assignment#02Assignment#02
Assignment#02
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Assignment#06
Assignment#06Assignment#06
Assignment#06
 
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick LearningOracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Introduction to MySQL - Part 2
Introduction to MySQL - Part 2Introduction to MySQL - Part 2
Introduction to MySQL - Part 2
 
Mysql quick guide
Mysql quick guideMysql quick guide
Mysql quick guide
 
Sqlharshal
SqlharshalSqlharshal
Sqlharshal
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Sql commands
Sql commandsSql commands
Sql commands
 

Similar to Sql 
statements , functions & joins

Similar to Sql 
statements , functions & joins (20)

Sql
SqlSql
Sql
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdf
 
Sql
SqlSql
Sql
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
DDL and DML statements.pptx
DDL and DML statements.pptxDDL and DML statements.pptx
DDL and DML statements.pptx
 
Sql
SqlSql
Sql
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
SQL
SQLSQL
SQL
 
SQL
SQL SQL
SQL
 
SQL
SQLSQL
SQL
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Java class 8
Java class 8Java class 8
Java class 8
 
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
 
Spufi
SpufiSpufi
Spufi
 

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

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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...Drew Madelung
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Sql 
statements , functions & 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 A query/command to perform a task in a database.
  • 5. CREATE ALTER Data Definition Language(DDL) DROP INSERT UPDATE Data Manipulation Language (DML) DELETE GRANT REVOKE Data Control Language(DCL)
  • 6. DDL - Data Definition Language 1. Create To Create a Database. Syntax : create database databasename; Eg : create database student; 2. Use Syntax : use databasename; Eg : use student;
  • 7. To Create Table Syntax : create table <TableName> ( ColumnName1 Datatype(Size) Constraint , ColumnName2 Datatype(Size) Constraint , ------------------------------------------------------- ); Eg : create table tbl_student ( pk_int_roll_no int(4) not null primary key, vchr_name varchar(20), char_gender char(2) );
  • 8. 3. Alter Table To change the structure of the table. alter table tbl_student add (int_marks int(2)); alter table tbl_student drop column char_gender; alter table tbl_student change vchr_name vchr_name varchar(30); 4. Drop Table To remove the tables. Syntax : drop table tablename; Eg : drop table tbl_student;
  • 9. DML - Data Manipulation Language 1. Insert To insert rows into a table. Syntax : insert into tablename(columnname1,columnname2,…)values(value1,value2,…); Eg : insert into tbl_student(pk_int_roll_no,vchr_name,int_marks)values(1,’Anu’,96);
  • 10. 2. Select To extract data from the database. (SELECT identifies what columns FROM identifies which table) Syntax : select * / [distinct]column_name from table_name where [condition]; Eg : •select * from tbl_student; •select pk_int_roll_no,vchr_name from tbl_student; •select vchr_name from tbl_student where int_marks>80;
  • 11. 3. Update To change the contents(rows /columns) of the table. Syntax : update tablename set columnname=values where condition; Eg : update tbl_student set int_marks=89 where pk_int_roll_no=2;
  • 12. 4. Delete To delete rows from the table. Syntax : delete from tablename where [condition]; Eg : delete from tbl_student where int_marks<40;
  • 13. DCL - Data Controll Language 1. Grant Syntax : grant privilage_type on tablename to ‘user_name'@'localhost'; Eg : grant all on tbl_student to ‘manu’@’localhost’;
  • 14. 2 . Revoke Syntax : revoke privilege_type on table_name from ‘user_name'@'localhost'; Eg : revoke select on tbl_student from ‘manu'@'localhost';
  • 16. SQL - Functions SQL functions are used for performing calculations on data. Types of Functions Aggregate Functions Scalar Functions
  • 17. Aggregate Functions •The functions that can be applied to all rows in table or to a subset of the table specified by the where clause. •Functions return single value for a group of rows in the table. •Sum() •Avg() •Min() •Max() •Count()
  • 18. pk_int_roll_no vchr_name int_marks 1 Anu 96 2 Veena 89 3 Amal 79 4 Reema 92 •select max(int_marks),min(int_marks),avg(int_marks) from tbl_student; Max(int_marks) min(int_marks) avg(int_marks) 96 79 81.7
  • 19. •select count(pk_int_roll_no)as total_students from tbl_student; total_students 4
  • 20. Group By To group the result set by one or more column. Often used in conjunction with aggregate function. Syntax : Select column_name, aggregate_function(column_name) from table_name group by column_name; Eg : Select vchr_name,sum(int_marks) from tbl_student group by vchr_name;
  • 21. Scalar function These functions return a single value for each values of a particular column given as input. •Lcase() •Ucase() •Round() Eg : Select ucase(vchr_name) from tbl_student; Select lcase(vchr_name) from tbl_student; Select round(int_marks) from tbl_student where pk_int_roll_no=3;
  • 22. JOINS
  • 23. JOINS To combine rows from two or more tables. Types of Joins :: 1. Inner join 2. Outer join a) Left join b) Right join
  • 24. INNER JOIN Returns all rows when there is at least one match in BOTH tables. Syntax : select column_name(s) from table1 join table2 on table1.column_name=table2.column_name;
  • 25. select stud_name,dept_name from tbl_student join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 2 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS stud_name dept_name Anu CS Veena QS Abhi EC John CS I n n e r j o i n
  • 26. LEFT OUTER JOIN Returns all rows from the left table (table1), with the matching rows in the right table (table2). Syntax : select column_name(s) from table1 left join table2 on table1.column_name=table2.column_name;
  • 27. select stud_name,dept_name from tbl_student left join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 4 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS l e f t j o i n stud_name dept_name Anu CS Veena QS Abhi NULL John CS
  • 28. RIGHT OUTER JOIN Return all rows from the right table, and the matched rows from the left table. Syntax : select column_name(s) from table1 right join table2 on table1.column_name=table2.column_name;
  • 29. select stud_name,dept_name from tbl_student lright join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 4 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS R i g h t j o i n stud_name dept_name Anu CS Veena QS Abhi NULL John CS
  • 30. 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.
  • 31. 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
  • 32. 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