SlideShare a Scribd company logo
1 of 41
Download to read offline
MySQL for business developer
Titouan BENOIT – CTO at Welp.fr
titouan.benoit@gmx.fr
MySQL for business developer– Titouan BENOIT
Titouan BENOIT – CTO at Welp
– titouan@welp.today
– titouan.benoit@gmx.fr
MySQL for business developer - v1.0 2
Titouan BENOIT
Plan
MySQL for business developer - v1.0 3
MySQL for business developer– Titouan BENOIT
1. Introduction
2. Query Language
3. Basics
– SELECT
– WHERE
– ORDER BY
– DISTINCT
– LIMIT & OFFSET
4. Advanced
– JOIN
– Sub-queries
– Math functions
– COUNT, SUM, AVG
5. phpMyAdmin
6. Examples/Exercices
MYSQL FOR BUSINESS DEVELOPER
1. Introduction
4
MySQL is an Open Source Relational Database Management System
(RDBMS)
– SQL (Structured Query Language) databases
– The second most used in the world
– Main purpose: storing data
In this presentation you will learn to:
– Make basics queries to search data into MySQL databases
– Extract data from MySQL databases
– Use PHPMyAdmin
– Compute statistics on data (count, average, …)
1. Introduction
MySQL for business developer - v1.0 5
MySQL for business developer– Titouan BENOIT
1. Introduction: structure
MySQL for business developer - v1.0 6
MySQL for business developer– Titouan BENOIT
MySQL Server
Databases
Welp OHA …
Tables
needs
propositions
users
…
id title author_id …
1 Mon titre1 5 …
2 Mon titre2 84 …
3 Mon titre3 6 …
… … … …
data
Columns
Rows
MYSQL FOR BUSINESS DEVELOPER
2. Query Language
7
SQL (Structured Query Language)
With SQL we can:
– Insert data
– Make queries (select data)
– Update data
– Delete data
– Create and modify schema (tables)
– Manage data access control
2. Query Language
MySQL for business developer - v1.0 8
MySQL for business developer– Titouan BENOIT
MYSQL FOR BUSINESS DEVELOPER
3. Basics
9
SELECT * FROM database.table;
– Select all colums from table in the database
– Tips:
• USE database;
SELECT * FROM table
SELECT column1, column2, … FROM table
Alias: SELECT user.email FROM fos_user AS user
Example:
– SELECT id, email, first_name, last_name FROM welp_db.fos_user
3. Basics: SELECT
MySQL for business developer - v1.0 10
MySQL for business developer– Titouan BENOIT
SELECT * FROM table WHERE condition;
– Select all colums from table in the database where condition is true
SELECT first_name, evaluation_average FROM fos_user WHERE evaluation_average = 5
– Select users where their average is equal to 5
Comparison operators Logical Operators
3. Basics: WHERE
MySQL for business developer - v1.0 11
MySQL for business developer– Titouan BENOIT
Operator Description
= equal
< less than
<= less than or equal to
> greater than
>= greater than or equal to
<> or != different, not equal
<=> Equal (also to NULL value)
Operator Symbol Description
AND && AND
OR || OR
XOR Exclusive OR
NOT ! NOT
Example:
SELECT * FROM table ORDER BY column1;
– Select all colums from table and order by column1 descending order (default behavior)
SELECT * FROM table ORDER BY column1 DESC;
– Descending order
SELECT * FROM table ORDER BY column1 ASC;
– Ascending order
SELECT * FROM table ORDER BY column1, column2, …;
– Multicolumn order
– Note: the order of column after ORDER BY statement is important. The order will be done on the column1 and then column2, …
3. Basics: ORDER BY
MySQL for business developer - v1.0 12
MySQL for business developer– Titouan BENOIT
SELECT DISTINCT column FROM table;
– Return only different rows (one by ‘column’ occurrences)
Example:
– SELECT DISTINCT species FROM animal;
– If I have 300 dogs, 400 cats and 250 elephants, this query will return:
• Dog
• Cat
• Elephant
– SELECT DISTINCT first_name FROM fos_user ORDER BY first_name ASC
3. Basics: DISTINCT
MySQL for business developer - v1.0 13
MySQL for business developer– Titouan BENOIT
SELECT * FROM table LIMIT 0,10;
– Return 10 rows from the beginning (row number 0).
– How to use limit: LIMIT [offset, ]number_of_lines
– Note: the LIMIT statement must be at the end
Other syntaxe:
– LIMIT number_of_lines [OFFSET offset];
Examples
3. Basics: LIMIT & OFFSET
MySQL for business developer - v1.0 14
MySQL for business developer– Titouan BENOIT
MYSQL FOR BUSINESS DEVELOPER
4. Advanced
15
INNER JOIN
– SELECT need.title, need.category_id, category.id, category.name FROM need
INNER JOIN category ON need.category_id = category.id
ORDER BY need.created_at
LIMIT 10;
– Note: inner join does not select rows where the relation is null (here where need has no category for example)
4. Advanced: JOIN
MySQL for business developer - v1.0 16
MySQL for business developer– Titouan BENOIT
Need table Category table
need category
INNER JOIN
LEFT JOIN
– SELECT user.first_name, media.id AS mediaID, media.name AS avatar
FROM fos_user AS user
LEFT JOIN media ON user.avatar_id = media.id
ORDER BY user.created_at DESC
LIMIT 10, 10
4. Advanced: JOIN
MySQL for business developer - v1.0 17
MySQL for business developer– Titouan BENOIT
User table Media table
media
LEFT JOIN
RIGHT JOIN
– SELECT category.id as categoryID, category.name AS categoryName, event.id AS eventID, event.title AS eventTitle
FROM event
RIGHT JOIN category ON event.category_id = category.id
4. Advanced: JOIN
MySQL for business developer - v1.0 18
MySQL for business developer– Titouan BENOIT
Category table Event table
Difference with LEFT JOINThis category
has no event
This event has no category
RIGHT JOIN LEFT JOIN
Sub-queries
– In FROM statement:
• SELECT goodEvaluation.comment, goodEvaluation.evaluation, goodEvaluation.evaluator_id
FROM (
SELECT *
FROM evaluation
WHERE evaluation.evaluation = 5
) as goodEvaluation
WHERE goodEvaluation.evaluator_id = 19
– In WHERE clause:
• SELECT id, title, category_id
FROM need
WHERE category_id IN (
SELECT id
FROM category
WHERE name IN ('Actions à plusieurs', 'Visites de courtoisie')
);
4. Advanced: sub-queries
MySQL for business developer - v1.0 19
MySQL for business developer– Titouan BENOIT
The sub-query:
Math functions
– CEIL(n) or CEILING(n): Return the smallest integer value not less than the argument
– FLOOR(n): Return the largest integer value not greater than the argument
– ROUND(n, d): Round the argument (d number of decimal)
– TRUNCATE(n, d): truncate the argument (d number of decimal)
– POW(n, e) or POWER(n, e): n^e
– SQRT(n): square root of the argument
– MOD(n, div): modulo of the division n/div
– RAND(): return a random value between 0 and 1
– SIGN(): return -1 for 0 and negative values and 1 for positive value
– ABS(): absolute value
– PI()
– COS()
– SIN()
4. Advanced: Math functions
MySQL for business developer - v1.0 20
MySQL for business developer– Titouan BENOIT
Aggregate functions:
– COUNT(), SUM(), AVG(), MAX(), MIN()
SELECT COUNT(*) as nbNeed FROM need WHERE need.category_id = 1
SELECT AVG(fos_user.evaluation_average) as avgEvaluation FROM fos_user
GROUP BY & HAVING
– SELECT u.id, u.first_name, COUNT(n.author_id) need_count
FROM fos_user u
LEFT JOIN need n ON n.author_id = u.id
GROUP BY u.id
HAVING need_count > 0
ORDER BY need_count DESC
4. Advanced: COUNT, SUM, AVG
MySQL for business developer - v1.0 21
MySQL for business developer– Titouan BENOIT
MYSQL FOR BUSINESS DEVELOPER
5. phpMyAdmin
22
Databases
5. phpMyAdmin
MySQL for business developer - v1.0 23
MySQL for business developer– Titouan BENOIT
Tables
5. phpMyAdmin
MySQL for business developer - v1.0 24
MySQL for business developer– Titouan BENOIT
Table structure
5. phpMyAdmin
MySQL for business developer - v1.0 25
MySQL for business developer– Titouan BENOIT
Browse data
5. phpMyAdmin
MySQL for business developer - v1.0 26
MySQL for business developer– Titouan BENOIT
SQL query
5. phpMyAdmin
MySQL for business developer - v1.0 27
MySQL for business developer– Titouan BENOIT
Export data
5. phpMyAdmin
MySQL for business developer - v1.0 28
MySQL for business developer– Titouan BENOIT
MYSQL FOR BUSINESS DEVELOPER
6. Examples/Exercices
29
Requirements:
– Connect to Welp phpMyAdmin
– Login to prod with the read only user
1 slide with the problem at stake and the next slide the query
Good luck & have fun!
6. Examples/Exercices
MySQL for business developer - v1.0 30
MySQL for business developer– Titouan BENOIT
1°/ Retrieve the id, title and the
category_id of the 10 last created_at need
6. Examples/Exercices
MySQL for business developer - v1.0 31
MySQL for business developer– Titouan BENOIT
1°/ SOLUTION
SELECT id, title, category_id, created_at FROM need
ORDER BY created_at DESC LIMIT 10
6. Examples/Exercices
MySQL for business developer - v1.0 32
MySQL for business developer– Titouan BENOIT
2°/ Retrieve the id, first_name and the rank of fos_user
which has a rank more than or equal to 2 and less than 5
and sort by rank (descending)
6. Examples/Exercices
MySQL for business developer - v1.0 33
MySQL for business developer– Titouan BENOIT
2°/ SOLUTION
SELECT id, first_name, rank
FROM fos_user
WHERE rank >= 2 AND rank < 5
ORDER BY rank DESC
6. Examples/Exercices
MySQL for business developer - v1.0 34
MySQL for business developer– Titouan BENOIT
3°/ Retrieve all the distinct place_locality as city of the
need and sort them by alphabetical order
6. Examples/Exercices
MySQL for business developer - v1.0 35
MySQL for business developer– Titouan BENOIT
3°/ SOLUTION
SELECT DISTINCT(place_locality) as city
FROM need
ORDER BY city ASC
6. Examples/Exercices
MySQL for business developer - v1.0 36
MySQL for business developer– Titouan BENOIT
4°/ Retrieve the 12 last created need with their category.
Display the need id, title and the category id and name.
6. Examples/Exercices
MySQL for business developer - v1.0 37
MySQL for business developer– Titouan BENOIT
4°/ SOLUTION
SELECT need.id as needID, need.title as needTitle, need.category_id, category.id as
categoryID, category.name as categoryName
FROM need
INNER JOIN category ON need.category_id = category.id
ORDER BY need.created_at DESC
LIMIT 12
6. Examples/Exercices
MySQL for business developer - v1.0 38
MySQL for business developer– Titouan BENOIT
5°/ Retrieve fos_user id, first_name, last_name and for
each user display their number of welpActions.
Hint: use GROUP BY user.id
6. Examples/Exercices
MySQL for business developer - v1.0 39
MySQL for business developer– Titouan BENOIT
5°/ SOLUTION
SELECT user.id, user.first_name, user.last_name,
COUNT(welp_action.user_id) as WelpActions
FROM fos_user as user
LEFT JOIN welp_action ON user.id = welp_action.user_id
GROUP BY user.id
ORDER BY WelpActions DESC
6. Examples/Exercices
MySQL for business developer - v1.0 40
MySQL for business developer– Titouan BENOIT
MySQL for business developer– Titouan BENOIT
MySQL for business developer
– https://en.wikipedia.org/wiki/MySQL
– https://en.wikipedia.org/wiki/SQL
– http://dev.mysql.com/
– https://openclassrooms.com/courses/administrez-vos-bases-de-donnees-avec-mysql
– http://dev.mysql.com/doc/refman/5.7/en/logical-operators.html
– http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html
– http://dev.mysql.com/doc/refman/5.7/en/join.html
– https://dev.mysql.com/doc/refman/5.0/en/group-by-handling.html
– http://dev.mysql.com/doc/refman/5.7/en/subqueries.html
– http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html
MySQL for business developer - v1.0 41
SOURCES

More Related Content

Similar to MySQL for business developer - Titouan BENOIT

MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8Frederic Descamps
 
MySQL Best Practices - OTN
MySQL Best Practices - OTNMySQL Best Practices - OTN
MySQL Best Practices - OTNRonald Bradford
 
Track 2 session 4 db2 for z os optimizer- what’s new in db2 11 and exploiti...
Track 2 session 4   db2 for z os optimizer- what’s new in db2 11 and exploiti...Track 2 session 4   db2 for z os optimizer- what’s new in db2 11 and exploiti...
Track 2 session 4 db2 for z os optimizer- what’s new in db2 11 and exploiti...IBMSystemzEvents
 
How to Contribute Code to MySQL?
How to Contribute Code to MySQL?How to Contribute Code to MySQL?
How to Contribute Code to MySQL?Thava Alagu
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling PresentationTommy Falgout
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
Discard inport exchange table & tablespace
Discard inport exchange table & tablespaceDiscard inport exchange table & tablespace
Discard inport exchange table & tablespaceMarco Tusa
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016Mir Mahmood
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1MariaDB plc
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMoshe Kaplan
 
ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 Rehan Zaidi
 
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsRehan Zaidi
 
Best Practices with ODI : Flexibility
Best Practices with ODI : FlexibilityBest Practices with ODI : Flexibility
Best Practices with ODI : FlexibilityGurcan Orhan
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informaticaBhuvana Priya
 

Similar to MySQL for business developer - Titouan BENOIT (20)

MariaDB workshop
MariaDB workshopMariaDB workshop
MariaDB workshop
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8
 
MySQL Best Practices - OTN
MySQL Best Practices - OTNMySQL Best Practices - OTN
MySQL Best Practices - OTN
 
Track 2 session 4 db2 for z os optimizer- what’s new in db2 11 and exploiti...
Track 2 session 4   db2 for z os optimizer- what’s new in db2 11 and exploiti...Track 2 session 4   db2 for z os optimizer- what’s new in db2 11 and exploiti...
Track 2 session 4 db2 for z os optimizer- what’s new in db2 11 and exploiti...
 
How to Contribute Code to MySQL?
How to Contribute Code to MySQL?How to Contribute Code to MySQL?
How to Contribute Code to MySQL?
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Discard inport exchange table & tablespace
Discard inport exchange table & tablespaceDiscard inport exchange table & tablespace
Discard inport exchange table & tablespace
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplan
 
ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1
 
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
 
Best Practices with ODI : Flexibility
Best Practices with ODI : FlexibilityBest Practices with ODI : Flexibility
Best Practices with ODI : Flexibility
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informatica
 

Recently uploaded

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 

Recently uploaded (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

MySQL for business developer - Titouan BENOIT

  • 1. MySQL for business developer Titouan BENOIT – CTO at Welp.fr titouan.benoit@gmx.fr
  • 2. MySQL for business developer– Titouan BENOIT Titouan BENOIT – CTO at Welp – titouan@welp.today – titouan.benoit@gmx.fr MySQL for business developer - v1.0 2 Titouan BENOIT
  • 3. Plan MySQL for business developer - v1.0 3 MySQL for business developer– Titouan BENOIT 1. Introduction 2. Query Language 3. Basics – SELECT – WHERE – ORDER BY – DISTINCT – LIMIT & OFFSET 4. Advanced – JOIN – Sub-queries – Math functions – COUNT, SUM, AVG 5. phpMyAdmin 6. Examples/Exercices
  • 4. MYSQL FOR BUSINESS DEVELOPER 1. Introduction 4
  • 5. MySQL is an Open Source Relational Database Management System (RDBMS) – SQL (Structured Query Language) databases – The second most used in the world – Main purpose: storing data In this presentation you will learn to: – Make basics queries to search data into MySQL databases – Extract data from MySQL databases – Use PHPMyAdmin – Compute statistics on data (count, average, …) 1. Introduction MySQL for business developer - v1.0 5 MySQL for business developer– Titouan BENOIT
  • 6. 1. Introduction: structure MySQL for business developer - v1.0 6 MySQL for business developer– Titouan BENOIT MySQL Server Databases Welp OHA … Tables needs propositions users … id title author_id … 1 Mon titre1 5 … 2 Mon titre2 84 … 3 Mon titre3 6 … … … … … data Columns Rows
  • 7. MYSQL FOR BUSINESS DEVELOPER 2. Query Language 7
  • 8. SQL (Structured Query Language) With SQL we can: – Insert data – Make queries (select data) – Update data – Delete data – Create and modify schema (tables) – Manage data access control 2. Query Language MySQL for business developer - v1.0 8 MySQL for business developer– Titouan BENOIT
  • 9. MYSQL FOR BUSINESS DEVELOPER 3. Basics 9
  • 10. SELECT * FROM database.table; – Select all colums from table in the database – Tips: • USE database; SELECT * FROM table SELECT column1, column2, … FROM table Alias: SELECT user.email FROM fos_user AS user Example: – SELECT id, email, first_name, last_name FROM welp_db.fos_user 3. Basics: SELECT MySQL for business developer - v1.0 10 MySQL for business developer– Titouan BENOIT
  • 11. SELECT * FROM table WHERE condition; – Select all colums from table in the database where condition is true SELECT first_name, evaluation_average FROM fos_user WHERE evaluation_average = 5 – Select users where their average is equal to 5 Comparison operators Logical Operators 3. Basics: WHERE MySQL for business developer - v1.0 11 MySQL for business developer– Titouan BENOIT Operator Description = equal < less than <= less than or equal to > greater than >= greater than or equal to <> or != different, not equal <=> Equal (also to NULL value) Operator Symbol Description AND && AND OR || OR XOR Exclusive OR NOT ! NOT Example:
  • 12. SELECT * FROM table ORDER BY column1; – Select all colums from table and order by column1 descending order (default behavior) SELECT * FROM table ORDER BY column1 DESC; – Descending order SELECT * FROM table ORDER BY column1 ASC; – Ascending order SELECT * FROM table ORDER BY column1, column2, …; – Multicolumn order – Note: the order of column after ORDER BY statement is important. The order will be done on the column1 and then column2, … 3. Basics: ORDER BY MySQL for business developer - v1.0 12 MySQL for business developer– Titouan BENOIT
  • 13. SELECT DISTINCT column FROM table; – Return only different rows (one by ‘column’ occurrences) Example: – SELECT DISTINCT species FROM animal; – If I have 300 dogs, 400 cats and 250 elephants, this query will return: • Dog • Cat • Elephant – SELECT DISTINCT first_name FROM fos_user ORDER BY first_name ASC 3. Basics: DISTINCT MySQL for business developer - v1.0 13 MySQL for business developer– Titouan BENOIT
  • 14. SELECT * FROM table LIMIT 0,10; – Return 10 rows from the beginning (row number 0). – How to use limit: LIMIT [offset, ]number_of_lines – Note: the LIMIT statement must be at the end Other syntaxe: – LIMIT number_of_lines [OFFSET offset]; Examples 3. Basics: LIMIT & OFFSET MySQL for business developer - v1.0 14 MySQL for business developer– Titouan BENOIT
  • 15. MYSQL FOR BUSINESS DEVELOPER 4. Advanced 15
  • 16. INNER JOIN – SELECT need.title, need.category_id, category.id, category.name FROM need INNER JOIN category ON need.category_id = category.id ORDER BY need.created_at LIMIT 10; – Note: inner join does not select rows where the relation is null (here where need has no category for example) 4. Advanced: JOIN MySQL for business developer - v1.0 16 MySQL for business developer– Titouan BENOIT Need table Category table need category INNER JOIN
  • 17. LEFT JOIN – SELECT user.first_name, media.id AS mediaID, media.name AS avatar FROM fos_user AS user LEFT JOIN media ON user.avatar_id = media.id ORDER BY user.created_at DESC LIMIT 10, 10 4. Advanced: JOIN MySQL for business developer - v1.0 17 MySQL for business developer– Titouan BENOIT User table Media table media LEFT JOIN
  • 18. RIGHT JOIN – SELECT category.id as categoryID, category.name AS categoryName, event.id AS eventID, event.title AS eventTitle FROM event RIGHT JOIN category ON event.category_id = category.id 4. Advanced: JOIN MySQL for business developer - v1.0 18 MySQL for business developer– Titouan BENOIT Category table Event table Difference with LEFT JOINThis category has no event This event has no category RIGHT JOIN LEFT JOIN
  • 19. Sub-queries – In FROM statement: • SELECT goodEvaluation.comment, goodEvaluation.evaluation, goodEvaluation.evaluator_id FROM ( SELECT * FROM evaluation WHERE evaluation.evaluation = 5 ) as goodEvaluation WHERE goodEvaluation.evaluator_id = 19 – In WHERE clause: • SELECT id, title, category_id FROM need WHERE category_id IN ( SELECT id FROM category WHERE name IN ('Actions à plusieurs', 'Visites de courtoisie') ); 4. Advanced: sub-queries MySQL for business developer - v1.0 19 MySQL for business developer– Titouan BENOIT The sub-query:
  • 20. Math functions – CEIL(n) or CEILING(n): Return the smallest integer value not less than the argument – FLOOR(n): Return the largest integer value not greater than the argument – ROUND(n, d): Round the argument (d number of decimal) – TRUNCATE(n, d): truncate the argument (d number of decimal) – POW(n, e) or POWER(n, e): n^e – SQRT(n): square root of the argument – MOD(n, div): modulo of the division n/div – RAND(): return a random value between 0 and 1 – SIGN(): return -1 for 0 and negative values and 1 for positive value – ABS(): absolute value – PI() – COS() – SIN() 4. Advanced: Math functions MySQL for business developer - v1.0 20 MySQL for business developer– Titouan BENOIT
  • 21. Aggregate functions: – COUNT(), SUM(), AVG(), MAX(), MIN() SELECT COUNT(*) as nbNeed FROM need WHERE need.category_id = 1 SELECT AVG(fos_user.evaluation_average) as avgEvaluation FROM fos_user GROUP BY & HAVING – SELECT u.id, u.first_name, COUNT(n.author_id) need_count FROM fos_user u LEFT JOIN need n ON n.author_id = u.id GROUP BY u.id HAVING need_count > 0 ORDER BY need_count DESC 4. Advanced: COUNT, SUM, AVG MySQL for business developer - v1.0 21 MySQL for business developer– Titouan BENOIT
  • 22. MYSQL FOR BUSINESS DEVELOPER 5. phpMyAdmin 22
  • 23. Databases 5. phpMyAdmin MySQL for business developer - v1.0 23 MySQL for business developer– Titouan BENOIT
  • 24. Tables 5. phpMyAdmin MySQL for business developer - v1.0 24 MySQL for business developer– Titouan BENOIT
  • 25. Table structure 5. phpMyAdmin MySQL for business developer - v1.0 25 MySQL for business developer– Titouan BENOIT
  • 26. Browse data 5. phpMyAdmin MySQL for business developer - v1.0 26 MySQL for business developer– Titouan BENOIT
  • 27. SQL query 5. phpMyAdmin MySQL for business developer - v1.0 27 MySQL for business developer– Titouan BENOIT
  • 28. Export data 5. phpMyAdmin MySQL for business developer - v1.0 28 MySQL for business developer– Titouan BENOIT
  • 29. MYSQL FOR BUSINESS DEVELOPER 6. Examples/Exercices 29
  • 30. Requirements: – Connect to Welp phpMyAdmin – Login to prod with the read only user 1 slide with the problem at stake and the next slide the query Good luck & have fun! 6. Examples/Exercices MySQL for business developer - v1.0 30 MySQL for business developer– Titouan BENOIT
  • 31. 1°/ Retrieve the id, title and the category_id of the 10 last created_at need 6. Examples/Exercices MySQL for business developer - v1.0 31 MySQL for business developer– Titouan BENOIT
  • 32. 1°/ SOLUTION SELECT id, title, category_id, created_at FROM need ORDER BY created_at DESC LIMIT 10 6. Examples/Exercices MySQL for business developer - v1.0 32 MySQL for business developer– Titouan BENOIT
  • 33. 2°/ Retrieve the id, first_name and the rank of fos_user which has a rank more than or equal to 2 and less than 5 and sort by rank (descending) 6. Examples/Exercices MySQL for business developer - v1.0 33 MySQL for business developer– Titouan BENOIT
  • 34. 2°/ SOLUTION SELECT id, first_name, rank FROM fos_user WHERE rank >= 2 AND rank < 5 ORDER BY rank DESC 6. Examples/Exercices MySQL for business developer - v1.0 34 MySQL for business developer– Titouan BENOIT
  • 35. 3°/ Retrieve all the distinct place_locality as city of the need and sort them by alphabetical order 6. Examples/Exercices MySQL for business developer - v1.0 35 MySQL for business developer– Titouan BENOIT
  • 36. 3°/ SOLUTION SELECT DISTINCT(place_locality) as city FROM need ORDER BY city ASC 6. Examples/Exercices MySQL for business developer - v1.0 36 MySQL for business developer– Titouan BENOIT
  • 37. 4°/ Retrieve the 12 last created need with their category. Display the need id, title and the category id and name. 6. Examples/Exercices MySQL for business developer - v1.0 37 MySQL for business developer– Titouan BENOIT
  • 38. 4°/ SOLUTION SELECT need.id as needID, need.title as needTitle, need.category_id, category.id as categoryID, category.name as categoryName FROM need INNER JOIN category ON need.category_id = category.id ORDER BY need.created_at DESC LIMIT 12 6. Examples/Exercices MySQL for business developer - v1.0 38 MySQL for business developer– Titouan BENOIT
  • 39. 5°/ Retrieve fos_user id, first_name, last_name and for each user display their number of welpActions. Hint: use GROUP BY user.id 6. Examples/Exercices MySQL for business developer - v1.0 39 MySQL for business developer– Titouan BENOIT
  • 40. 5°/ SOLUTION SELECT user.id, user.first_name, user.last_name, COUNT(welp_action.user_id) as WelpActions FROM fos_user as user LEFT JOIN welp_action ON user.id = welp_action.user_id GROUP BY user.id ORDER BY WelpActions DESC 6. Examples/Exercices MySQL for business developer - v1.0 40 MySQL for business developer– Titouan BENOIT
  • 41. MySQL for business developer– Titouan BENOIT MySQL for business developer – https://en.wikipedia.org/wiki/MySQL – https://en.wikipedia.org/wiki/SQL – http://dev.mysql.com/ – https://openclassrooms.com/courses/administrez-vos-bases-de-donnees-avec-mysql – http://dev.mysql.com/doc/refman/5.7/en/logical-operators.html – http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html – http://dev.mysql.com/doc/refman/5.7/en/join.html – https://dev.mysql.com/doc/refman/5.0/en/group-by-handling.html – http://dev.mysql.com/doc/refman/5.7/en/subqueries.html – http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html MySQL for business developer - v1.0 41 SOURCES