SlideShare a Scribd company logo
1 of 34
SQL
Ahmed Farag
Information Systems Dept.
Faculty of Computers and Information
Menoufia University, Egypt.
Review
• Install MySQL, Work Bench
• Load sample Data to DB
• Select
• DISTINCT,
• WHERE, Not IN, IN, AND, OR, BETWEEN, Like, Is
null, Is Not Null, Alias
• Limit, Order by
• Sub Queries
• Trim function
MySQL
Functions
1. MySQL Multi row functions
2. MySQL single row functions
MySQL
Functions
MySQL single row functions
INSTR function
• Locate a substring in a string or to check if a substring
exists in a string.
• Returns the position of the first occurrence of a
substring in a string. If the substring is not found in the
str, the INSTR function returns zero (0).
• The syntax of the INSTR function:
• INSTR(str,substr);
• The INSTR function accepts two arguments:
• The str is the string that you want to search in.
• The substr is the substring that you want to search
for.
INSTR function examples
• SELECT INSTR('MySQL INSTR', 'MySQL’);
• SELECT INSTR('MySQL INSTR', BINARY 'mysql');
INSTR function examples
• SELECT
• productName
• FROM
• products
• WHERE
• INSTR(productname,'Car') > 0;
CONCAT
function
• Concatenate two or more strings together.
• The MySQL CONCAT function takes one or more string
arguments and concatenates them into a single string.
• The CONCAT function requires a minimum of one
parameter otherwise it raises an error.
• The syntax of the CONCAT function:
• CONCAT(string1,string2, ... );
• The CONCAT function converts all arguments to the
string type before concatenating. If any argument is
NULL, the CONCAT function returns a NULL value.
CONCAT function examples
• SELECT 'MySQL ' 'String ' 'Concatenation’;
• SELECT CONCAT('MySQL','CONCAT’);
• SELECT CONCAT('MySQL',NULL,'CONCAT');
CONCAT function examples
• SELECT
• concat(contactFirstName,' ',contactLastName) Fullname
• FROM
• customers;
CONCAT_WS
function
• MySQL provides a special form of the CONCAT function:
CONCAT_WS function.
• The CONCAT_WS function concatenates two or more
string values with a predefined separator.
• The syntax of the CONCAT_WS function:
• CONCAT_WS(seperator,string1,string2, ... );
• The first argument is the separator for other arguments:
string1, string2, …
• The CONCAT_WS function adds the separator between
string arguments and returns a single string with the
separator inserted between string arguments.
• The CONCAT_WS function returns NULL if and only if
the first argument, which is the separator, is NULL.
CONCAT_WS function examples
• SELECT CONCAT_WS(',','John','Doe’);
• SELECT CONCAT_WS(NULL ,'Jonathan', 'Smith’);
• SELECT CONCAT_WS(',','Jonathan', 'Smith',NULL);
CONCAT_WS function examples
• Using Customer Table:
Customer_Address
---------------------------------------------------
Schmitt Carine
54, rue Royale
44000 Nantes
France
King Jean
8489 Strong St.
83030 Las Vegas
USA
FIND_IN_SET
function
• Allows you to find the position of a string within a
comma-separated list of strings.
• The syntax of the FIND_IN_SET function.
• FIND_IN_SET(needle,haystack);
• The FIND_IN_SET function returns an integer or a NULL
value depending on the value of the arguments:
• Return a NULL value if either needle or haystack is
NULL.
• Return zero if the needle is not in the haystack or
the haystack is an empty string.
• Return a positive integer if the needle is in the
haystack.
FIND_IN_SET function examples
• SELECT FIND_IN_SET('y','x,y,z'); -- 2
• SELECT FIND_IN_SET('a','x,y,z'); -- 0
• SELECT FIND_IN_SET('a',''); -- 0
• SELECT FIND_IN_SET(NULL,'x,y,z’); --NULL
• SELECT FIND_IN_SET('a',NULL); --NULL
FIND_IN_SET function examples
• SELECT
• name, colors
• FROM
• products
• WHERE
• FIND_IN_SET('red’, colors);
Round function
• The ROUND() is a mathematical function that allows you
to round a number to a specified number of decimal
places.
MOD function
• The MOD() function returns the remainder of one
number divided by another.
TRUNCATE
function
• MySQL TRUNCATE() function truncates a number to a
specified number of decimal places.
MySQL
Functions
MySQL Multi row functions
AVG function
• The MySQL AVG() function is an aggregate function that
allows you to calculate the average value of a set of
values or an expression.
COUNT function
• Count the number rows in a table.
• The COUNT function returns the number of rows in a
table. The COUNT function allows you to count all rows
in a table or rows that match a particular condition.
• There are several forms of the COUNT function:
COUNT(*), COUNT(expression) and COUNT(DISTINCT
expression).
SUM function
• calculate the sum of a set of values or an expression.
• If you use the SUM() function in a SELECT statement
that returns no matching row, the SUM() function
returns NULL, not zero.
• The DISTINCT operator allows you to calculate distinct
values in the set.
• The SUM() function ignores the NULL values in the
calculation.
MIN function
• find the minimum value in a set of values.
• The MIN function returns the minimum value in a set of
values. The MIN function is very useful in some
scenarios such as finding the smallest number,
selecting the least expensive product, getting the
lowest credit limit, etc.
MAX function
• The MySQL MAX function returns the maximum value in
a set of values. The MAX function is handy in many
queries such as finding the greatest number, the most
expensive product, and the largest payment from
customers.
Group By Divide the data to more groups
Group By
• Group rows into subgroups based on values of columns or expressions.
• The GROUP BY clause returns one row for each group. In other words, it
reduces the number of rows in the result set.
• The GROUP BY clause must appear after the FROM and WHERE clauses.
• Syntax:
SELECT
c1, c2,..., cn, aggregate_function(ci)
FROM
table
WHERE
where_conditions
GROUP BY c1 , c2,...,cn;
Having Restrict the groups displayed
Having
• specify a filter condition for groups of rows or aggregates.
• The HAVING clause is used in the SELECT statement to specify filter
conditions for a group of rows or aggregates.
• The HAVING clause is often used with the GROUP BY clause to filter
groups based on a specified condition.
• Notice that the HAVING clause applies a filter condition to each group
of rows, while the WHERE clause applies the filter condition to each
individual row.
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having

More Related Content

What's hot

MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle SqlAhmed Yaseen
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functionsNitesh Singh
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statementSyed Zaid Irshad
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and OperatorsMohan Kumar.R
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize outputSyed Zaid Irshad
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracleLogan Palanisamy
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-convertedSUSHANTPHALKE2
 

What's hot (17)

MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
Sql select
Sql select Sql select
Sql select
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
Sql operator
Sql operatorSql operator
Sql operator
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-converted
 
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
 

Similar to MYSQL single rowfunc-multirowfunc-groupby-having

Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1mlraviol
 
What’s New in MariaDB Server 10.2
What’s New in MariaDB Server 10.2What’s New in MariaDB Server 10.2
What’s New in MariaDB Server 10.2MariaDB plc
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharmaaioughydchapter
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sqlpgolhar
 
Alasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAlasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAndrey Gershun
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Apache Cassandra Data Modeling with Travis Price
Apache Cassandra Data Modeling with Travis PriceApache Cassandra Data Modeling with Travis Price
Apache Cassandra Data Modeling with Travis PriceDataStax Academy
 

Similar to MYSQL single rowfunc-multirowfunc-groupby-having (20)

Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
 
Linq
LinqLinq
Linq
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 
What’s New in MariaDB Server 10.2
What’s New in MariaDB Server 10.2What’s New in MariaDB Server 10.2
What’s New in MariaDB Server 10.2
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
 
Sql functions
Sql functionsSql functions
Sql functions
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
Alasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAlasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User Manual
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
QBIC
QBICQBIC
QBIC
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Apache Cassandra Data Modeling with Travis Price
Apache Cassandra Data Modeling with Travis PriceApache Cassandra Data Modeling with Travis Price
Apache Cassandra Data Modeling with Travis Price
 

More from Ahmed Farag

Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBAhmed Farag
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Ahmed Farag
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++Ahmed Farag
 

More from Ahmed Farag (10)

Intro to php
Intro to phpIntro to php
Intro to php
 
Normalization
NormalizationNormalization
Normalization
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
OOP C++
OOP C++OOP C++
OOP C++
 
Functions C++
Functions C++Functions C++
Functions C++
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
Intro to C++
Intro to C++Intro to C++
Intro to C++
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
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
 
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
 
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
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
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
 
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
 
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
 

MYSQL single rowfunc-multirowfunc-groupby-having

  • 1. SQL Ahmed Farag Information Systems Dept. Faculty of Computers and Information Menoufia University, Egypt.
  • 2. Review • Install MySQL, Work Bench • Load sample Data to DB • Select • DISTINCT, • WHERE, Not IN, IN, AND, OR, BETWEEN, Like, Is null, Is Not Null, Alias • Limit, Order by • Sub Queries • Trim function
  • 3. MySQL Functions 1. MySQL Multi row functions 2. MySQL single row functions
  • 5. INSTR function • Locate a substring in a string or to check if a substring exists in a string. • Returns the position of the first occurrence of a substring in a string. If the substring is not found in the str, the INSTR function returns zero (0). • The syntax of the INSTR function: • INSTR(str,substr); • The INSTR function accepts two arguments: • The str is the string that you want to search in. • The substr is the substring that you want to search for.
  • 6. INSTR function examples • SELECT INSTR('MySQL INSTR', 'MySQL’); • SELECT INSTR('MySQL INSTR', BINARY 'mysql');
  • 7. INSTR function examples • SELECT • productName • FROM • products • WHERE • INSTR(productname,'Car') > 0;
  • 8. CONCAT function • Concatenate two or more strings together. • The MySQL CONCAT function takes one or more string arguments and concatenates them into a single string. • The CONCAT function requires a minimum of one parameter otherwise it raises an error. • The syntax of the CONCAT function: • CONCAT(string1,string2, ... ); • The CONCAT function converts all arguments to the string type before concatenating. If any argument is NULL, the CONCAT function returns a NULL value.
  • 9. CONCAT function examples • SELECT 'MySQL ' 'String ' 'Concatenation’; • SELECT CONCAT('MySQL','CONCAT’); • SELECT CONCAT('MySQL',NULL,'CONCAT');
  • 10. CONCAT function examples • SELECT • concat(contactFirstName,' ',contactLastName) Fullname • FROM • customers;
  • 11. CONCAT_WS function • MySQL provides a special form of the CONCAT function: CONCAT_WS function. • The CONCAT_WS function concatenates two or more string values with a predefined separator. • The syntax of the CONCAT_WS function: • CONCAT_WS(seperator,string1,string2, ... ); • The first argument is the separator for other arguments: string1, string2, … • The CONCAT_WS function adds the separator between string arguments and returns a single string with the separator inserted between string arguments. • The CONCAT_WS function returns NULL if and only if the first argument, which is the separator, is NULL.
  • 12. CONCAT_WS function examples • SELECT CONCAT_WS(',','John','Doe’); • SELECT CONCAT_WS(NULL ,'Jonathan', 'Smith’); • SELECT CONCAT_WS(',','Jonathan', 'Smith',NULL);
  • 13. CONCAT_WS function examples • Using Customer Table: Customer_Address --------------------------------------------------- Schmitt Carine 54, rue Royale 44000 Nantes France King Jean 8489 Strong St. 83030 Las Vegas USA
  • 14. FIND_IN_SET function • Allows you to find the position of a string within a comma-separated list of strings. • The syntax of the FIND_IN_SET function. • FIND_IN_SET(needle,haystack); • The FIND_IN_SET function returns an integer or a NULL value depending on the value of the arguments: • Return a NULL value if either needle or haystack is NULL. • Return zero if the needle is not in the haystack or the haystack is an empty string. • Return a positive integer if the needle is in the haystack.
  • 15. FIND_IN_SET function examples • SELECT FIND_IN_SET('y','x,y,z'); -- 2 • SELECT FIND_IN_SET('a','x,y,z'); -- 0 • SELECT FIND_IN_SET('a',''); -- 0 • SELECT FIND_IN_SET(NULL,'x,y,z’); --NULL • SELECT FIND_IN_SET('a',NULL); --NULL
  • 16. FIND_IN_SET function examples • SELECT • name, colors • FROM • products • WHERE • FIND_IN_SET('red’, colors);
  • 17. Round function • The ROUND() is a mathematical function that allows you to round a number to a specified number of decimal places.
  • 18. MOD function • The MOD() function returns the remainder of one number divided by another.
  • 19. TRUNCATE function • MySQL TRUNCATE() function truncates a number to a specified number of decimal places.
  • 21. AVG function • The MySQL AVG() function is an aggregate function that allows you to calculate the average value of a set of values or an expression.
  • 22. COUNT function • Count the number rows in a table. • The COUNT function returns the number of rows in a table. The COUNT function allows you to count all rows in a table or rows that match a particular condition. • There are several forms of the COUNT function: COUNT(*), COUNT(expression) and COUNT(DISTINCT expression).
  • 23. SUM function • calculate the sum of a set of values or an expression. • If you use the SUM() function in a SELECT statement that returns no matching row, the SUM() function returns NULL, not zero. • The DISTINCT operator allows you to calculate distinct values in the set. • The SUM() function ignores the NULL values in the calculation.
  • 24. MIN function • find the minimum value in a set of values. • The MIN function returns the minimum value in a set of values. The MIN function is very useful in some scenarios such as finding the smallest number, selecting the least expensive product, getting the lowest credit limit, etc.
  • 25. MAX function • The MySQL MAX function returns the maximum value in a set of values. The MAX function is handy in many queries such as finding the greatest number, the most expensive product, and the largest payment from customers.
  • 26. Group By Divide the data to more groups
  • 27. Group By • Group rows into subgroups based on values of columns or expressions. • The GROUP BY clause returns one row for each group. In other words, it reduces the number of rows in the result set. • The GROUP BY clause must appear after the FROM and WHERE clauses. • Syntax: SELECT c1, c2,..., cn, aggregate_function(ci) FROM table WHERE where_conditions GROUP BY c1 , c2,...,cn;
  • 28. Having Restrict the groups displayed
  • 29. Having • specify a filter condition for groups of rows or aggregates. • The HAVING clause is used in the SELECT statement to specify filter conditions for a group of rows or aggregates. • The HAVING clause is often used with the GROUP BY clause to filter groups based on a specified condition. • Notice that the HAVING clause applies a filter condition to each group of rows, while the WHERE clause applies the filter condition to each individual row.

Editor's Notes

  1. SELECT     productname FROM     products WHERE     productname LIKE '%Car%';
  2. SELECT     CONCAT_WS(CHAR(13),             CONCAT_WS(' ', contactLastname, contactFirstname),             addressLine1,             addressLine2,             CONCAT_WS(' ', postalCode, city),             country,             CONCAT_WS(CHAR(13), '')) AS Customer_Address FROM     customers;