SQL provides powerful but reasonably simple tools for data analysis and handling. Mike McClellan, the Senior Product Manager for Paddle8, took beginners through the basics of SQL. He talked about the SQL queries needed to collect data from a database, even if it lives in different places and analyze it to find the answers you’re looking for.
He taught the understanding of essential SQL skills that allow developers to write queries against single and multiple tables, manipulate data in tables, and create database objects.
9. ABOUT ME 9PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
About Me
Senior Product ManagerCURRENT
ROLE
PRIOR
EXPERIENCE
EDUCATION
Project Manager
QA Analyst
A.B. in Economics and
Government & Legal Studies
10. AGENDA 10PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Agenda
So, what is SQL?
Let’s cover the basics
How the data is stored
How a query is constructed
Utilizing conditions, logical operations, calculations, and functions
Joining tables together
How does this help with product management?
SQL Tools and online resources
11. WHAT IS SQL? 11PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
What is SQL?
SQL, or Structured Query Language, is a computer language used for retrieving,
manipulating, and storing data in a relational database.
Common relational database management systems that use SQL include
Oracle, Microsoft SQL Server, Access, and MySQL.
12. LET’S COVER THE BASICS 12PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
A relational database is organized by tables
A relational database organizes data into one or more tables
Each table typically represents one entity
Tables are uniquely identified by their names and are constructed to have
relationships with other tables
13. LET’S COVER THE BASICS 13PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
A table stores data in columns and rows
Tables organize data into smaller entities called fields; a field is a column in a
table that maintains specific information about every row in a table
A row, or record, is a horizontal entity that represents individual entries in a
table.
A column is a vertical entity that contains all data for a specific field in a table
Each column has a specified name, datatype (i.e. datetime, varchar, int), and
attribute (i.e. length, format)
14. LET’S COVER THE BASICS 14PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Important traits of a relational database
Constraints - rules enforced on data columns to limit the type of data that can go
into a table to ensure accuracy and reliability (i.e. NOT NULL constraint)
Primary keys - uniquely identifies each record in a database table column
Foreign keys - uniquely identifies a record in another database table column
15. LET’S COVER THE BASICS 15PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Standard SQL commands
SELECT - extracts data from the database
INSERT - inserts new data into the database
UPDATE - updates existing data in the database
DELETE - deletes data from the database
CREATE - creates a new table
DROP - deletes a table
Different Relational Database Systems will have their own extensions of
16. LET’S COVER THE BASICS 16PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
How a SELECT statement is structured
The SELECT statement is used to retrieve data from the database and is stored
in a result table known as a result-set
Every SELECT statement will have the same basic structure:
SELECT (the fields you want returned) from (the specified table);
or put another way:
SELECT column1, column2 from table_name
17. LET’S COVER THE BASICS 17PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Using the SELECT statement
Example:
SELECT first_name, last_name from Customers;
Example:
To select all columns from a table, use ‘*’ instead of the column names
SELECT * from Customers;
18. LET’S COVER THE BASICS 18PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Using the WHERE clause to limit results
● The WHERE clause is used with the SELECT statement to restrict the result-
set by filtering on specific values:
SELECT column1, column2 from table_name WHERE column1 = 'value';
● Example:
○ SELECT * from Customers WHERE first_name = 'Tom';
19. LET’S COVER THE BASICS 19PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Using logical operations to further limit results
The AND and OR operators can be used with the WHERE clause to filter results
based on more than one condition
For the AND operator, results will surface only if conditions on both sides of the AND operator
are true
For the OR operator, results will surface if a condition on either of the OR operator is true
20. LET’S COVER THE BASICS 20PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Using logical operations to further limit results
SELECT name, league from Products WHERE year > 2012 AND league = 'NFL';
SELECT name, league from Products WHERE year < 2012 OR league = 'MLB';
21. LET’S COVER THE BASICS 21PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Using logical operations to further limit results
IN and BETWEEN are other useful operators; they will return all records where
the condition is true
SELECT last_name, email from Customers WHERE first_name IN ('David','Paul')
SELECT name from Products WHERE year BETWEEN 2012 AND 2016
The LIKE operator combined with “%” can be used for string matching
SELECT * from Products WHERE name like '%Super Bowl%'
22. LET’S COVER THE BASICS 22PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Other ways to manipulate data and/or limit results
Standard Math calculations (+, -, *, /)
Calculations are done at the record level
SELECT name, salary, salary + '5000', salary + (salary/2) from Employees WHERE start_date
> 2014
23. LET’S COVER THE BASICS 23PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Other ways to manipulate data and/or limit results
Aggregate functions (COUNT, MAX, MIN, SUM, AVG)
Aggregate functions return results based on evaluating column data
SELECT COUNT(ID) from Products WHERE year = 2017
SELECT SUM(salary) from Employees WHERE department = 'Finance'
SELECT MAX(salary) from Employees WHERE department = 'Engineering'
24. LET’S COVER THE BASICS 24PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Other ways to manipulate data and/or limit results
The GROUP BY statement is often used with aggregate functions. It works by
aggregating rows together based on a specified column and performing
functions on one or more other columns
SELECT department, SUM(salary) from Employees WHERE start_date > 2016
GROUP BY department;
25. LET’S COVER THE BASICS 25PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Other ways to manipulate data and/or limit results
Using ORDER BY sorts the result-set in ascending or descending order based
on the specified column
By default, it sorts in ascending order; use ASC or DESC to distinguish how you
want to order results
Combined with LIMIT can help filter results even further
select name, salary from Employees WHERE department = 'Operations'
ORDER BY salary DESC
LIMIT 3
26. LET’S COVER THE BASICS 26PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Joining tables together to evaluate more data
Joins are used to combine records from one or more tables based on a related
column between them
Joining different tables together allows us to write a single SELECT statement
to evaluate the combined dataset
This is where the Primary Keys and Foreign Keys are important
There are multiple kinds of joins, but we’ll focus on INNER JOIN and LEFT
JOIN
27. LET’S COVER THE BASICS 27PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Joining tables together to evaluate more data
INNER JOIN combines rows from both tables as long as there is a match
between the columns tied together
If there are rows that do not have a match, these records will not be part of the
combined dataset
28. LET’S COVER THE BASICS 28PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Joining tables together to evaluate more data
SELECT city, team, year from Teams
INNER JOIN Titles on Titles.team_id = Teams.ID
29. LET’S COVER THE BASICS 29PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Joining tables together to evaluate more data
The LEFT JOIN is less restrictive than INNER JOIN when it comes to filtering
out data.
Using the LEFT JOIN will return all records from the left-side table and records
from the right-side table if there is a match.
If there is no match with the right-side table then those results appear as NULL
30. LET’S COVER THE BASICS 30PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Joining tables together to evaluate more data
SELECT city, team, year from Teams
LEFT JOIN Titles on Titles.team_id = Teams.ID
31. LET’S COVER THE BASICS 31PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Combining it all
We can apply the same operators, functions, etc. on joined tables as we did when
writing a SELECT statement against a single table; allowing us to build a
more robust result-set
SELECT city, team, count(year) from Teams
INNER JOIN Titles on Titles.team_id = Teams.ID
WHERE year < '2017' AND (city LIKE '%New York%' OR city LIKE '%Boston%')
GROUP BY city, team
ORDER BY COUNT(year) ASC
32. HOW SQL HELPS A PRODUCT MANAGER 32PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
How does this help as a Product Manager?
Product development and writing requirements
Prioritization
Understanding, monitoring, and measuring user behavior
33. HOW SQL HELPS A PRODUCT MANAGER 33PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Product Development and Requirements
Understanding how the front-end and back-end tie together is incredibly useful
when putting requirements together.
Knowing what data is captured (or is not captured) and how it is structured will
help with determining the scope of work.
34. HOW SQL HELPS A PRODUCT MANAGER 34PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Prioritization
SQL is a great tool to quantitatively determine backlog priority for both features
and issues that need to be addressed.
Combining this with qualitative analysis helps to better form decisions and
message reasoning to different stakeholders.
35. HOW SQL HELPS A PRODUCT MANAGER 35PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Understanding, monitoring, and measuring user behavior
SQL makes it easier to combine and analyze event-tracking data with system
data
The ability to tie user data with event-data helps better how users are engaging
with your product; what is failing and what is working.
Combined with qualitative analysis, you can use SQL to determine baseline KPIs
and measure the impact of a new feature.
Also gives insight to help know what is unknown; understanding and knowing
what data is captured can help determine if event tracking needs to changed
as user behavior changes.
36. HOW SQL HELPS A PRODUCT MANAGER 36PRODUCT SCHOOL INTRO TO SQL FOR BEGINNERS
Useful tools and online resources
Analytics tools utilizing SQL
Looker
Periscope
Mode
Online resources
Code Academy
Code School
For those of you new here to our meetup, Product School offers 8-week, part-time courses on how to be a product manager.
We also offer a program called Coding for Managers. This course is for professionals without a technical background who want to learn how to code, build a better rapport with engineer teams and increase visibility with hiring managers.
If you'd like a free ticket to our next event, be sure to tweet a picture of your presenter using @productschool or check-in to the event on facebook. Following the presentation, please come show me and I'll take your email to send your free ticket.