SlideShare a Scribd company logo
Sql statements function join
NikhilDevS.B
nikhildevsb@gmail.com
www.facebook.com/nikhildevsb
TwitterProfile
www.linkedin.com/nikhildevsb
Typing speed: 24 wpm.
SQL STATEMENTS , FUNCTIONS AND JOINS
Disclaimer: This presentation is prepared by trainees of
baabtra.com as a part of mentoring program. This is not
official document of baabtra.com – Mentoring Partner
SQL
Structured Query Language
SQL is Special purpose programming language designed
for managing data held in Relational Data Base
Management System(RDBMS)
SQL STATEMENTS
• Data Definition Language (DDL)
- Define database structure/schema.
• Data Manipulation Language (DML)
-Manipulation on table data.
Query one or more tables.
• Data Control Language (DCL)
-Set database permissions and privileges.
DDL Statements are :
CRAETE
ALTER
DROP
TRUNCATE
DML Statements are :
INSERT
SELECT
UPDATE
DELETE
DCL Statements
GRANT
ROLLBACK
REVOKE
Tables in SQL
PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
MultiTouch $203.99 Household Hitachi
Product
Attribute/field/
column
Table name
Tuples or rows
DDL Commands
• CREATE - To create objects in data base.
o CREATE DATABASE <database name>;
E.g. CREATE DATABASE db_student;
o CREATE TABLE tablename
(
field1 datatype,
field2 datatype
);
E.g. CREATE TABLE tbl_student(vchr_name varchar(20),int_roll int);
vchr_name int_roll
NULL NULL
• ALTER – Alter the structure of database. i.e., to add or drop
columns on existing table.
ALTER TABLE tablename ADD column datatype;//add column
ALTER TABLE tablename DROP column; //delete a column
E.g. ALTER TABLE tbl_student ADD int_mark int; //added new
column mark of
type integer
E.g. ALTER TABLE tbl_student DROP int_mark; //deleted mark
vchr_name int_roll int_mark
NULL NULL NULL
• TRUNCATE – To remove all records from table.
TRUNCATE TABLE tablename;
E.g. TRUNCATE TABLE tbl_student;
• RENAME - to rename a table
RENAME TABLE oldname TO newname’;
E.g. RENAME TABLE tbl_student TO tbl_studentrecord;
DML Commands
• INSERT – Add data into the table.
insert into table_name values(data1,data2,...);
insert into tbl_student values(‘john’, 11);
tbl_student
vchr_name int_roll
john 11
• UPDATE – to update a value in a table.
UPDATE table_name SET column_name=value WHERE condition.
E.g. UPDATE tbl_student set vchr_name=‘james’ where chr_name=‘john’;
vchr_name int_roll
steve 10
james 11
vchr_name int_roll
steve 10
john 11
Before update
After update
• DELETE – to delete a row from table.
DELETE FROM tablename ;
DELETE from tbl_student where chr_name=‘james’;
pk_id vchr_name int_roll
1 steve 10
2 james 11
Before deletion
After deletion
pk_id vchr_name int_roll
1 steve 10
• SELECT – Retrieve data from database.
SELECT column FROM tablename;
E.g1. SELECT * FROM tbl_student; //gives all columns of table
pk_id vchr_name int_roll
1 steve 10
2 James 11
E.g2. SELECT pk_id,vchr_name FROM tbl_student; //gives
specified columns of table
pk_id vchr_name
1 steve
2 james
Functions
1.Aggregate function
2.Scalar functions
Aggregate Functions
Function that returns a single value, calculated from values
in column.
• SUM() – returns sum of column.
• COUNT() – returns number of rows.
• AVG() – returns average value of column.
• MIN() – returns smallest value of column.
• MAX() – returns largest value of column.
• LAST() – returns the last value.
• FIRST() – returns the first value.
Use of aggregate functions.
SELECT avg(emp_count), sum(emp_count), max(emp_count)
min(emp_count), count(emp_count) from tbl_employee;
brnch_num brnch_name region_num emp_count
108 New york 100 10
110 Boston 100 6
21 Chicago 200 5
404 San Diego 400 6
415 San jose 400 3
avg(emp_count) sum(emp_count) max(emp_count) min(emp_count) count(emp_count)
6 30 10 3 5
Scalar Functions
Function that returns a single value, based on input value.
• UCASE() – converts a field to upper case.
• LCASE() - converts a field to lower case.
• LEN() – returns the length of a text filed.
• ROUND() – rounds a numeric field to number of decimal
specified
SELECT UCASE(column_name) FROM table_name;
JOIN OPERATION
Combine rows from two or more tables, based on a common
field between them.
• INNER JOIN (SIMPLE JOIN OR JOIN) – Returns rows when there is a
match in both tables
• OUTER JOIN –Returns all the rows of both table whether it has matched
or not
-LEFT OUTER JOIN (LEFT JOIN) – Returns all rows from left
table and matched rows from right table.
- RIGHT OUTER JOIN (RIGHT JOIN)- Returns all rows from
right table and matched rows from left table
Pk_emp_id vchr_emp_name vchr_company
1 James Dell
2 John Sony
3 Albert Hp
Pk_desig_id vchr_desig
1 System
engineer
2 Tester
4 Tech support
Tbl_emp Tbl_empdesig
SELECT * FROM tbl_emp JOIN tbl_empdesig on
tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id
Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig
1 James Delll 1 System engineer
2 john Sony 2 Tester
E.g. JOIN
Common value
LEFT OUTER JOIN
Pk_emp_id vchr_emp_name Chr_company
1 James Dell
2 John Sony
3 Albert Hp
Pk_desig_id vchr_desig
1 System
engineer
2 Tester
4 Tech support
Tbl_emp Tbl_empdesig
SELECT * FROM tbl_emp LEFT JOIN tbl_empdesig on
tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id
Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig
1 James Delll 1 System engineer
2 john Sony 2 Tester
3 Albert Hp Null null
RIGHT OUTER JOIN
Pk_emp_id vchr_emp_name vchr_company
1 James Dell
2 John Sony
3 Albert Hp
Pk_desig_id vchr_desig
1 System
engineer
2 Tester
4 Tech support
Tbl_emp Tbl_empdesig
SELECT * FROM tbl_emp RIGHT JOIN tbl_empdesig on
tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id
Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig
1 James Delll 1 System engineer
2 john Sony 2 Tester
null null null 4 Tech suport
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

PPTX
Sql basic things
PPTX
Data processing by Neeraj Bhandari ( Surkhet.Nepal )
PPT
Quality Analysis in Apparel industry
PDF
Critical Path Analysis
PPT
Data base management system (dbms)
PPTX
Group By, Order By, and Aliases in SQL
PPT
Sweater production process
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
Sql basic things
Data processing by Neeraj Bhandari ( Surkhet.Nepal )
Quality Analysis in Apparel industry
Critical Path Analysis
Data base management system (dbms)
Group By, Order By, and Aliases in SQL
Sweater production process
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples

What's hot (20)

PPTX
Practice of quality in apparel industry sector
PPTX
Data Color In Textile
PPTX
Tech Pack.pptx
DOC
80 different SQL Queries with output
PPTX
Sql commands
PPTX
Computerized cutting machine
PDF
Industrial Attachment undertaken at Knit Concern Group Limited
PPTX
garment manufacturing
PPTX
Responsibilities of merchandiser
PPTX
Textile Machineries
PPTX
SQL(DDL & DML)
PPT
Slub yarn fabric_samples
DOC
Oracle sql material
PPTX
stretch recovery of knitted fabric
PPTX
Sql queries presentation
DOCX
Astm standard on apparel (Source Copy)
PDF
Quality control in apparel industry of bangladesh
DOCX
T shirt spech sheet 2nd part
PPTX
Needle Loop & Sinker Loop
Practice of quality in apparel industry sector
Data Color In Textile
Tech Pack.pptx
80 different SQL Queries with output
Sql commands
Computerized cutting machine
Industrial Attachment undertaken at Knit Concern Group Limited
garment manufacturing
Responsibilities of merchandiser
Textile Machineries
SQL(DDL & DML)
Slub yarn fabric_samples
Oracle sql material
stretch recovery of knitted fabric
Sql queries presentation
Astm standard on apparel (Source Copy)
Quality control in apparel industry of bangladesh
T shirt spech sheet 2nd part
Needle Loop & Sinker Loop
Ad

Similar to Sql statements function join (20)

PPTX
Sql 
statements , functions & joins
PPTX
My SQL.pptx
PDF
Database Management System
PPTX
rdbms parul university oracle dbms bca mca
PPSX
Oracle Training in Kochi | Trivandrum |Thrissur
PDF
BCS4L1-Database Management lab.pdf
PPT
SQL || overview and detailed information about Sql
DOC
DOCX
It6312 dbms lab-ex2
PPTX
Data Manipulation Language.pptx
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPT
Sql Commands_Dr.R.Shalini.ppt
PPTX
SQL LECTURE.pptx
PDF
dbms lab manual
PPTX
MYSQL-database basic queries for good understanding
PPTX
Sql statement,functions and joins
PDF
Chapter8 my sql revision tour
PDF
Basics on SQL queries
Sql 
statements , functions & joins
My SQL.pptx
Database Management System
rdbms parul university oracle dbms bca mca
Oracle Training in Kochi | Trivandrum |Thrissur
BCS4L1-Database Management lab.pdf
SQL || overview and detailed information about Sql
It6312 dbms lab-ex2
Data Manipulation Language.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
Sql Commands_Dr.R.Shalini.ppt
SQL LECTURE.pptx
dbms lab manual
MYSQL-database basic queries for good understanding
Sql statement,functions and joins
Chapter8 my sql revision tour
Basics on SQL queries
Ad

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

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Sql statements function join

  • 3. Disclaimer: This presentation is prepared by trainees of baabtra.com as a part of mentoring program. This is not official document of baabtra.com – Mentoring Partner
  • 4. SQL Structured Query Language SQL is Special purpose programming language designed for managing data held in Relational Data Base Management System(RDBMS)
  • 5. SQL STATEMENTS • Data Definition Language (DDL) - Define database structure/schema. • Data Manipulation Language (DML) -Manipulation on table data. Query one or more tables. • Data Control Language (DCL) -Set database permissions and privileges.
  • 6. DDL Statements are : CRAETE ALTER DROP TRUNCATE DML Statements are : INSERT SELECT UPDATE DELETE DCL Statements GRANT ROLLBACK REVOKE
  • 7. Tables in SQL PName Price Category Manufacturer Gizmo $19.99 Gadgets GizmoWorks Powergizmo $29.99 Gadgets GizmoWorks SingleTouch $149.99 Photography Canon MultiTouch $203.99 Household Hitachi Product Attribute/field/ column Table name Tuples or rows
  • 8. DDL Commands • CREATE - To create objects in data base. o CREATE DATABASE <database name>; E.g. CREATE DATABASE db_student; o CREATE TABLE tablename ( field1 datatype, field2 datatype ); E.g. CREATE TABLE tbl_student(vchr_name varchar(20),int_roll int); vchr_name int_roll NULL NULL
  • 9. • ALTER – Alter the structure of database. i.e., to add or drop columns on existing table. ALTER TABLE tablename ADD column datatype;//add column ALTER TABLE tablename DROP column; //delete a column E.g. ALTER TABLE tbl_student ADD int_mark int; //added new column mark of type integer E.g. ALTER TABLE tbl_student DROP int_mark; //deleted mark vchr_name int_roll int_mark NULL NULL NULL
  • 10. • TRUNCATE – To remove all records from table. TRUNCATE TABLE tablename; E.g. TRUNCATE TABLE tbl_student; • RENAME - to rename a table RENAME TABLE oldname TO newname’; E.g. RENAME TABLE tbl_student TO tbl_studentrecord;
  • 11. DML Commands • INSERT – Add data into the table. insert into table_name values(data1,data2,...); insert into tbl_student values(‘john’, 11); tbl_student vchr_name int_roll john 11
  • 12. • UPDATE – to update a value in a table. UPDATE table_name SET column_name=value WHERE condition. E.g. UPDATE tbl_student set vchr_name=‘james’ where chr_name=‘john’; vchr_name int_roll steve 10 james 11 vchr_name int_roll steve 10 john 11 Before update After update
  • 13. • DELETE – to delete a row from table. DELETE FROM tablename ; DELETE from tbl_student where chr_name=‘james’; pk_id vchr_name int_roll 1 steve 10 2 james 11 Before deletion After deletion pk_id vchr_name int_roll 1 steve 10
  • 14. • SELECT – Retrieve data from database. SELECT column FROM tablename; E.g1. SELECT * FROM tbl_student; //gives all columns of table pk_id vchr_name int_roll 1 steve 10 2 James 11 E.g2. SELECT pk_id,vchr_name FROM tbl_student; //gives specified columns of table pk_id vchr_name 1 steve 2 james
  • 16. Aggregate Functions Function that returns a single value, calculated from values in column. • SUM() – returns sum of column. • COUNT() – returns number of rows. • AVG() – returns average value of column. • MIN() – returns smallest value of column. • MAX() – returns largest value of column. • LAST() – returns the last value. • FIRST() – returns the first value.
  • 17. Use of aggregate functions. SELECT avg(emp_count), sum(emp_count), max(emp_count) min(emp_count), count(emp_count) from tbl_employee; brnch_num brnch_name region_num emp_count 108 New york 100 10 110 Boston 100 6 21 Chicago 200 5 404 San Diego 400 6 415 San jose 400 3 avg(emp_count) sum(emp_count) max(emp_count) min(emp_count) count(emp_count) 6 30 10 3 5
  • 18. Scalar Functions Function that returns a single value, based on input value. • UCASE() – converts a field to upper case. • LCASE() - converts a field to lower case. • LEN() – returns the length of a text filed. • ROUND() – rounds a numeric field to number of decimal specified SELECT UCASE(column_name) FROM table_name;
  • 19. JOIN OPERATION Combine rows from two or more tables, based on a common field between them. • INNER JOIN (SIMPLE JOIN OR JOIN) – Returns rows when there is a match in both tables • OUTER JOIN –Returns all the rows of both table whether it has matched or not -LEFT OUTER JOIN (LEFT JOIN) – Returns all rows from left table and matched rows from right table. - RIGHT OUTER JOIN (RIGHT JOIN)- Returns all rows from right table and matched rows from left table
  • 20. Pk_emp_id vchr_emp_name vchr_company 1 James Dell 2 John Sony 3 Albert Hp Pk_desig_id vchr_desig 1 System engineer 2 Tester 4 Tech support Tbl_emp Tbl_empdesig SELECT * FROM tbl_emp JOIN tbl_empdesig on tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig 1 James Delll 1 System engineer 2 john Sony 2 Tester E.g. JOIN Common value
  • 21. LEFT OUTER JOIN Pk_emp_id vchr_emp_name Chr_company 1 James Dell 2 John Sony 3 Albert Hp Pk_desig_id vchr_desig 1 System engineer 2 Tester 4 Tech support Tbl_emp Tbl_empdesig SELECT * FROM tbl_emp LEFT JOIN tbl_empdesig on tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig 1 James Delll 1 System engineer 2 john Sony 2 Tester 3 Albert Hp Null null
  • 22. RIGHT OUTER JOIN Pk_emp_id vchr_emp_name vchr_company 1 James Dell 2 John Sony 3 Albert Hp Pk_desig_id vchr_desig 1 System engineer 2 Tester 4 Tech support Tbl_emp Tbl_empdesig SELECT * FROM tbl_emp RIGHT JOIN tbl_empdesig on tbl_emp.pk_emp_id=tbl_empdesig.pk_desig_id Pk_emp_id vchr_emp_name vchr_company Pk_desig_id vchr_desig 1 James Delll 1 System engineer 2 john Sony 2 Tester null null null 4 Tech suport
  • 24. 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.
  • 25. 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
  • 26. 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