SlideShare a Scribd company logo
1 of 33
Recall
• What is a database?
• What is DBMS?
• Examples for DDL,DML,DCL statements
• How can I retrieve a particular row from a
table?
Introduction to MySQL
Grouping, Scalar and aggregate functions, Joins
Day 2,Week 5
SQL Functions
• SQL has many built-in functions for
performing calculations on data. It can be
broadly classified in to two
–Aggregate Functions
– Scalar functions
SQL Functions
• Aggregate Functions
– SQL aggregate functions return a single value,
calculated from all the values in a column.
• Select AVG(int_price) from tbl_stock;
// returns 8
• Select SUM(int_price) from tbl_stock; // returns 33
• Select MIN(int_price) from tbl_stock; // returns 2
Pk_int_id Vchr_product Int_price
1 Pen 10
2 Book 15
3 Eraser 2
4 Pencil 6
Tbl_stock Select
SUM(int_price)
from tbl_stock;
Returns a single value
SQL Functions
• Scalar Functions
– SQL scalar functions return a single value for each
values of a particular column given as input.
• Select UCASE(vchr_product) from tbl_stock; // returns each
column value in capital letter
• Select LCASE(vchr_product) from tbl_stock; // returns each
column value in small letter
Pk_int_id Vchr_product Int_price
1 Pen 10
2 Book 15
3 Eraser 2
4 Pencil 6
Tbl_product
Returns a value
Returns a value
Returns a value
Returns a value
Grouping Data
• GROUP BY allows you to take your result set,
group it into logical groups and then run
aggregate queries on the groups.
• You could for instance select all employees,
group them by their workplace location and
calculate the average salary. This would give you
the average salary of an employee at a given
location in your database.Emp_id Emp_name Emp_age Emp_email int_salary vchr_place
1000 Deepak 24 dk@gmail.com 10000 Cochin
1001 Aneesh 23 an@gmail.com 20000 Calicut
1002 Naveen 25 nn@gmail.com 15000 Cochin
1003 Jacob 25 jb@gmail.com 13000 Calicut
Tbl_employee
Avg = 12500
Avg = 11500
Select vchr_place, avg(int_salary) from
tbl_employee group by vchr_place;
Example
Result :
Emp_id Emp_name Emp_age Emp_email int_salary vchr_place
1000 Deepak 24 dk@gmail.com 10000 Cochin
1001 Aneesh 23 an@gmail.com 20000 Calicut
1002 Naveen 25 nn@gmail.com 15000 Cochin
1003 Jacob 25 jb@gmail.com 13000 Calicut
Tbl_employee
Vchr_place Avg(int_alary)
Cochin 12500
Calicut 11500
The HAVING Clause
• The HAVING clause was added to SQL
because the WHERE keyword could not be
used with aggregate functions.
• An Sql statement can have both „where‟
clause and „having‟ clause. Where filteres
data before grouping.Having filters data after
grouping
• Syntax:
• SELECT column_name,
aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
Example
Select vchr_place, avg(int_salary) from
tbl_employee group by vchr_place
having avg(int_salary)>12000;
Vchr_place Avg(int_alary)
Cochin 12500
Calicut 11500
Vchr_place Avg(int_alary)
Cochin 12500
Joins
Where do we use joins?
• An SQL JOIN clause is used to combine rows from
two or more tables, based on a common field between
them.
• Join helps to write single query to fetch data from
multiple tables so as to meet the business
Types Of joins
• Inner join
• Outer Join
–Left Outer Join
–Right Outer Join
Inner Join
• The INNER JOIN keyword selects all rows
from both tables as long as there is a
match between the columns in both tables.
• Syntax
– SELECT column_name(s) FROM table1
INNER JOIN table2 ON
table1.column_name=table2.column_na
Pk_int_id Vchr_place
1 Mumbai
2 Kolkata
3 Bangalore
4 Cochin
Emp_id Emp_name fk_int_place_id
1000 Deepak 1
1001 Aneesh 3
1002 Naveen 2
1003 Jacob 5
Emp_id Emp_name Vchr_place
1000 Deepak Mumbai
1001 Aneesh Banglore
1002 Naveen Kolkatta
InnerJoin
Inner Join
SELECT emp_id,emp_name, vchr_place
from tbl_employee Join tbl_place on
fk_int_place_id=pk_int_id
Left Outer Join
• The LEFT JOIN keyword returns all rows from
the left table (table1), with the matching rows in
the right table (table2). The result is NULL in the
right side when there is no match.
SELECT column_name(s) FROM table1
LEFT JOIN table2 ON
Left Outer Join
Pk_int_id Vchr_place
1 Mumbai
2 Kolkata
3 Bangalore
4 Cochin
Emp_id Emp_name fk_int_place_id
1000 Deepak 1
1001 Aneesh 4
1002 Naveen 2
1003 Jacob 5
1004 Alex 6
Emp_id Emp_name Vchr_place
1000 Deepak Mumbai
1001 Aneesh Cochin
1002 Naveen Kolkatta
1003 Jacob NULL
1004 Alex NULL
LeftJoin
SELECT emp_id,emp_name, vchr_place
from tbl_employee Left Join tbl_place
on fk_int_place_id=pk_int_id
Right Outer Join
• The RIGHT JOIN keyword returns all rows from
the right table (table2), with the matching rows in
the left table (table1). The result is NULL in the
left side when there is no match.
SELECT column_name(s) FROM table1
RIGHT JOIN table2 ON
table1.column_name=table2.column_name;
Right Outer Join
Pk_int_id Vchr_place
1 Mumbai
2 Kolkata
3 Bangalore
4 Cochin
5 Trivandrum
7 Delhi
Emp_id Emp_name fk_int_place_id
1000 Deepak 1
1001 Aneesh 4
1002 Naveen 2
1003 Jacob 5
1004 Alex 6
Emp_id Emp_name Vchr_place
1000 Deepak Mumbai
1001 Aneesh Cochin
1002 Naveen Kolkatta
1003 Jacob Trivandrum
NULL NULL Banglore
NULL NULL Delhi
RightJoin
SELECT emp_id,emp_name, vchr_place from
tbl_employee Right Join tbl_place on
fk_int_place_id=pk_int_id
Questions?
“A good question deserve a good
grade…”
Self Check !!
Self Check !!
• Scalar function will return 0 or
more values
–True
–False
Self Check !!
• Scalar function will return 0 or
more values
–True
–False
Self Check !!
• Round() is an aggregate function
–True
–False
Self Check !!
• Round() is an aggregate function
–True
–False
Self Check !!
• Spot out the errors
Select dept,sum(salary), place from
tbl_employee group by dept where
sum(salary)>10000
Correct Answer:
Select dept,sum(salary) from tbl_employee group by
Self Check !!
• Spot out the errors
Select dept,sum(salary), place from
tbl_employee group by dept where
sum(salary)>10000
Correct Answer:
Select dept,sum(salary) from tbl_employee group by
Result will be unexpected if display any columns
without aggregate functions other than that
given in group by
Where must be given before group by We cannot use aggregate functions with where
condition
Select id,student,dept from
tbl_student join tbl_dept on
fk_dept_id =pk_int_id
Pk_int_id dept
1 Computer science
2 Electronics
3 Commerce
4 Art
id Student fk_dept_id
1000 Ram 1
1001 Raju 4
1002 Mary 2
1003 Dona 5
1004 Lal 6
id Student dept
1000 Ram Computer science
1001 Raju Art
1002 Mary Electronics
1003 Dona NULL
1004 Lal NULL
Query :
Select id,student,dept from
tbl_student left join tbl_dept on
fk_dept_id =pk_int_id
Pk_int_id dept
1 Computer science
2 Electronics
3 Commerce
4 Art
id Student fk_dept_id
1000 Ram 1
1001 Raju 4
1002 Mary 2
1003 Dona 5
1004 Lal 6
id Student dept
1000 Ram Computer science
1001 Raju Art
1002 Mary Electronics
1003 Dona NULL
1004 Lal NULL
Query :
Self Check !!
• When to use inner join
–I want to display all the places and
students from that places
–I want to display all the students and
their places
–I want to display only the students of
given places
–I want to display the only students from
Self Check !!
• When to use inner join
–I want to display all the places and
students from that places
–I want to display all the students and
their places
–I want to display only the students of
given places
–I want to display the only students from
Self Check !!
• When to use Right join
A. Matching records from right table
needs to be displayed
B. Mismatching records from right table
needs to be displayed
C. Matching records from left table needs
to be displayed
D. Mismatching records from left table
Self Check !!
• When to use Right join
A. Matching records from right table
needs to be displayed
B. Mismatching records from right table
needs to be displayed
C. Matching records from left table needs
to be displayed
D. Mismatching records from left table
End of day

More Related Content

What's hot

Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and SortingMuhammadBakri13
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQLRaajendra M
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharpMicheal Ogundero
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracleLogan Palanisamy
 
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 AssignmentArun Sial
 
[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26Kevin Chun-Hsien Hsu
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functionsNitesh Singh
 
Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joinsredro
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1asmhemu
 
Ms excel 2003 intermediate
Ms excel 2003 intermediateMs excel 2003 intermediate
Ms excel 2003 intermediateJason Wong
 
Functions reading passage
Functions reading passageFunctions reading passage
Functions reading passagebweldon
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 

What's hot (20)

Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
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
 
[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joins
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Ms excel 2003 intermediate
Ms excel 2003 intermediateMs excel 2003 intermediate
Ms excel 2003 intermediate
 
Binary tree
Binary treeBinary tree
Binary tree
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Functions reading passage
Functions reading passageFunctions reading passage
Functions reading passage
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Python list
Python listPython list
Python list
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
 

Similar to Introduction to mysql part 2

Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle DatabaseChhom Karath
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Vidyasagar Mundroy
 
Sql intro
Sql introSql intro
Sql introglubox
 
Integrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdfIntegrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdfSaikrishna492522
 
Dbms question
Dbms questionDbms question
Dbms questionRicky Dky
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operatorsAhmed Farag
 
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxUnit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxHAMEEDHUSSAINBU21CSE
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankpptnewrforce
 
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)Muhammed Thanveer M
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 

Similar to Introduction to mysql part 2 (20)

Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Sql
SqlSql
Sql
 
Sql statements function join
Sql statements function joinSql statements function join
Sql statements function join
 
Sql intro
Sql introSql intro
Sql intro
 
Integrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdfIntegrity constraint fundamentals of dbms.pdf
Integrity constraint fundamentals of dbms.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Dbms question
Dbms questionDbms question
Dbms question
 
sql language
sql languagesql language
sql language
 
Sql 
statements , functions & joins
Sql 
statements , functions  &  joinsSql 
statements , functions  &  joins
Sql 
statements , functions & joins
 
Sql statement,functions and joins
Sql statement,functions and joinsSql statement,functions and joins
Sql statement,functions and joins
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxUnit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
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)
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 

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 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 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
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 

Recently uploaded

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideStefan Dietze
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 

Recently uploaded (20)

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 

Introduction to mysql part 2

  • 1. Recall • What is a database? • What is DBMS? • Examples for DDL,DML,DCL statements • How can I retrieve a particular row from a table?
  • 2. Introduction to MySQL Grouping, Scalar and aggregate functions, Joins Day 2,Week 5
  • 3. SQL Functions • SQL has many built-in functions for performing calculations on data. It can be broadly classified in to two –Aggregate Functions – Scalar functions
  • 4. SQL Functions • Aggregate Functions – SQL aggregate functions return a single value, calculated from all the values in a column. • Select AVG(int_price) from tbl_stock; // returns 8 • Select SUM(int_price) from tbl_stock; // returns 33 • Select MIN(int_price) from tbl_stock; // returns 2 Pk_int_id Vchr_product Int_price 1 Pen 10 2 Book 15 3 Eraser 2 4 Pencil 6 Tbl_stock Select SUM(int_price) from tbl_stock; Returns a single value
  • 5. SQL Functions • Scalar Functions – SQL scalar functions return a single value for each values of a particular column given as input. • Select UCASE(vchr_product) from tbl_stock; // returns each column value in capital letter • Select LCASE(vchr_product) from tbl_stock; // returns each column value in small letter Pk_int_id Vchr_product Int_price 1 Pen 10 2 Book 15 3 Eraser 2 4 Pencil 6 Tbl_product Returns a value Returns a value Returns a value Returns a value
  • 6. Grouping Data • GROUP BY allows you to take your result set, group it into logical groups and then run aggregate queries on the groups. • You could for instance select all employees, group them by their workplace location and calculate the average salary. This would give you the average salary of an employee at a given location in your database.Emp_id Emp_name Emp_age Emp_email int_salary vchr_place 1000 Deepak 24 dk@gmail.com 10000 Cochin 1001 Aneesh 23 an@gmail.com 20000 Calicut 1002 Naveen 25 nn@gmail.com 15000 Cochin 1003 Jacob 25 jb@gmail.com 13000 Calicut Tbl_employee Avg = 12500 Avg = 11500
  • 7. Select vchr_place, avg(int_salary) from tbl_employee group by vchr_place; Example Result : Emp_id Emp_name Emp_age Emp_email int_salary vchr_place 1000 Deepak 24 dk@gmail.com 10000 Cochin 1001 Aneesh 23 an@gmail.com 20000 Calicut 1002 Naveen 25 nn@gmail.com 15000 Cochin 1003 Jacob 25 jb@gmail.com 13000 Calicut Tbl_employee Vchr_place Avg(int_alary) Cochin 12500 Calicut 11500
  • 8. The HAVING Clause • The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. • An Sql statement can have both „where‟ clause and „having‟ clause. Where filteres data before grouping.Having filters data after grouping • Syntax: • SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value
  • 9. Example Select vchr_place, avg(int_salary) from tbl_employee group by vchr_place having avg(int_salary)>12000; Vchr_place Avg(int_alary) Cochin 12500 Calicut 11500 Vchr_place Avg(int_alary) Cochin 12500
  • 10. Joins
  • 11. Where do we use joins? • An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. • Join helps to write single query to fetch data from multiple tables so as to meet the business
  • 12. Types Of joins • Inner join • Outer Join –Left Outer Join –Right Outer Join
  • 13. Inner Join • The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. • Syntax – SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_na
  • 14. Pk_int_id Vchr_place 1 Mumbai 2 Kolkata 3 Bangalore 4 Cochin Emp_id Emp_name fk_int_place_id 1000 Deepak 1 1001 Aneesh 3 1002 Naveen 2 1003 Jacob 5 Emp_id Emp_name Vchr_place 1000 Deepak Mumbai 1001 Aneesh Banglore 1002 Naveen Kolkatta InnerJoin Inner Join SELECT emp_id,emp_name, vchr_place from tbl_employee Join tbl_place on fk_int_place_id=pk_int_id
  • 15. Left Outer Join • The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. SELECT column_name(s) FROM table1 LEFT JOIN table2 ON
  • 16. Left Outer Join Pk_int_id Vchr_place 1 Mumbai 2 Kolkata 3 Bangalore 4 Cochin Emp_id Emp_name fk_int_place_id 1000 Deepak 1 1001 Aneesh 4 1002 Naveen 2 1003 Jacob 5 1004 Alex 6 Emp_id Emp_name Vchr_place 1000 Deepak Mumbai 1001 Aneesh Cochin 1002 Naveen Kolkatta 1003 Jacob NULL 1004 Alex NULL LeftJoin SELECT emp_id,emp_name, vchr_place from tbl_employee Left Join tbl_place on fk_int_place_id=pk_int_id
  • 17. Right Outer Join • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name;
  • 18. Right Outer Join Pk_int_id Vchr_place 1 Mumbai 2 Kolkata 3 Bangalore 4 Cochin 5 Trivandrum 7 Delhi Emp_id Emp_name fk_int_place_id 1000 Deepak 1 1001 Aneesh 4 1002 Naveen 2 1003 Jacob 5 1004 Alex 6 Emp_id Emp_name Vchr_place 1000 Deepak Mumbai 1001 Aneesh Cochin 1002 Naveen Kolkatta 1003 Jacob Trivandrum NULL NULL Banglore NULL NULL Delhi RightJoin SELECT emp_id,emp_name, vchr_place from tbl_employee Right Join tbl_place on fk_int_place_id=pk_int_id
  • 19. Questions? “A good question deserve a good grade…”
  • 21. Self Check !! • Scalar function will return 0 or more values –True –False
  • 22. Self Check !! • Scalar function will return 0 or more values –True –False
  • 23. Self Check !! • Round() is an aggregate function –True –False
  • 24. Self Check !! • Round() is an aggregate function –True –False
  • 25. Self Check !! • Spot out the errors Select dept,sum(salary), place from tbl_employee group by dept where sum(salary)>10000 Correct Answer: Select dept,sum(salary) from tbl_employee group by
  • 26. Self Check !! • Spot out the errors Select dept,sum(salary), place from tbl_employee group by dept where sum(salary)>10000 Correct Answer: Select dept,sum(salary) from tbl_employee group by Result will be unexpected if display any columns without aggregate functions other than that given in group by Where must be given before group by We cannot use aggregate functions with where condition
  • 27. Select id,student,dept from tbl_student join tbl_dept on fk_dept_id =pk_int_id Pk_int_id dept 1 Computer science 2 Electronics 3 Commerce 4 Art id Student fk_dept_id 1000 Ram 1 1001 Raju 4 1002 Mary 2 1003 Dona 5 1004 Lal 6 id Student dept 1000 Ram Computer science 1001 Raju Art 1002 Mary Electronics 1003 Dona NULL 1004 Lal NULL Query :
  • 28. Select id,student,dept from tbl_student left join tbl_dept on fk_dept_id =pk_int_id Pk_int_id dept 1 Computer science 2 Electronics 3 Commerce 4 Art id Student fk_dept_id 1000 Ram 1 1001 Raju 4 1002 Mary 2 1003 Dona 5 1004 Lal 6 id Student dept 1000 Ram Computer science 1001 Raju Art 1002 Mary Electronics 1003 Dona NULL 1004 Lal NULL Query :
  • 29. Self Check !! • When to use inner join –I want to display all the places and students from that places –I want to display all the students and their places –I want to display only the students of given places –I want to display the only students from
  • 30. Self Check !! • When to use inner join –I want to display all the places and students from that places –I want to display all the students and their places –I want to display only the students of given places –I want to display the only students from
  • 31. Self Check !! • When to use Right join A. Matching records from right table needs to be displayed B. Mismatching records from right table needs to be displayed C. Matching records from left table needs to be displayed D. Mismatching records from left table
  • 32. Self Check !! • When to use Right join A. Matching records from right table needs to be displayed B. Mismatching records from right table needs to be displayed C. Matching records from left table needs to be displayed D. Mismatching records from left table