SQL For Product Managers - HelloPM - Co
SQL For Product Managers - HelloPM - Co
definitive guide
© HELLOPM.CO
Product management is about taking your product in the right
direction with the fastest speed possible. Data is always going to be
an integral part of your decision-making, and having the ability to do
the primary analysis yourself can definitely boost your speed as a
product manager.
Depending on the type and scale of the organization that you are
working for, as a product manager you’ll have access to a lot of free
and paid tools available for data analysis, ranging from Google
Analytics, Mixpanel to Tableau, or PowerBI.
While these tools will add up to your productivity and analysis skills,
it’s better as a product manager to be as close to your data as
© HELLOPM.CO
possible. In most of the applications that you’re going to work with,
the data would be stored in something known as relational databases.
Once you develop a decent understanding of how these work and how
you can fetch the data and insights from these databases you’ll get a
better command of your product’s usage data.
What is SQL?
© HELLOPM.CO
Thus to understand SQL you need to learn three things:
© HELLOPM.CO
These tables could be related to each other through some common
columns (also known as foreign keys). Lets consider a very basic
example from instagram to understand this, a simplified database
structure (AKA data-schema) for instagram could look like this:
Table 1: Users
Columns: id, first_name, last_name, handle, registered_at, email_id
Table 2: Photos
Columns: id, user_id, photo_url, created_at, caption
Table 3: Likes
Columns: id, user_id, photo_id, created_at
When someone likes this photo, one new row is entered in the likes
table with the user_id of the person who has liked the photo, the id of
the photo which is liked and the time when the photo was liked.
© HELLOPM.CO
Now if you have been following closely till now, you would have
identified that the photos table is connected to the users table through
user_id, the likes table is connected to the users and photos table
through user_id and photo_id respectively.
The user_id in the photos table, the photo_id and user_id in the likes
table are examples of foreign keys.
Now that we know how data is stored in these tables, lets understand
how we can retrieve data from these tables to drive insights.
This is where SQL comes into play. Simplistically speaking, SQL is the
high-level language to give commands or ask questions to your
database.
© HELLOPM.CO
While you can use SQL to read, insert, update or delete data into
relational databases, as a product manager your scope of work will
always be limited to reading data.
Now let us understand how we can make some basic read queries to
our database through SQL.
If you want to see some data from any tables you will use the popular
‘SELECT’ query.
© HELLOPM.CO
SELECT {column name 1, column name 2} from table name
If you want to retrieve all the columns you can replace {column
names} with “*”.
Thus, to retrieve data from the users table in our instagram database,
we will use:
Filtering data
Now if you want to filter your data by some criteria, you can use the
‘WHERE’ clause, for example you want to name and date of
registration of the user whose email address is ‘john.doe@gmail.com’,
for such as case you will use:
© HELLOPM.CO
Apart from = condition, you can also use conditional statements such
as greater than (>), greater than equal to (>=), less than (<), less than
equal to (<=) or like to further define your filters.
Here are some example queries to help you understand this better:
Get list of people whose first names are either Ankit or Ankur
If you have a range of items to check from, you can use ‘WHERE IN’
clause, for example: to get list of people whose email addresses are
© HELLOPM.CO
‘a@gmail.com’, ‘b@gmail.com’, and ‘c@gmail.com’ you can use
following query:
That was about 80% of the knowledge you need to have on filtering
data, if you are interested in learning more please go to tutorialpoint to
expand your SQL knowledge.
Apart from filters there are two more important things which you as a
product manager should know: How to sort the data and how to limit
the amount of data you want to retrieve.
This query will give you list of users, with recently registered users on
the top (descending order of date of registration):
© HELLOPM.CO
This query will give you 10 recently registered users:
To get all the likes of a particular photo on instagram, you will use this
query:
© HELLOPM.CO
SELECT count(*), photo_id FROM Likes where photo_id = {photo_id}
To get the number of photos liked by any particular user (lets say
user_id = 20) you will use a query like this:
You can read more about different types of aggregate functions here
© HELLOPM.CO
JOINs in SQL – Using multiple tables together
Till now we have understood how you can filter, sort, limit, aggregate
and group data. Now the next and the most interesting part of SQL:
JOINS. Joins will help you connect two or more tables and unlock
insights which are spanned across multiple tables.
While this definition is enough for some of the common use cases,
you should definitely spend some time learning about different types
of joins here.
You now are aware of the most common SQL queries and terms that a
product manager should know about SQL.
© HELLOPM.CO
● How to filter data as per your requirements with WHERE, IN and
conditional statements
● How to Limit & Order your data for most efficiency
● How to aggregate data with aggregate functions and using
GROUP BY to make uncover important insights
● How to use simple joins to get data which is available across
multiple tables
One pressing question that will come to the minds of some readers is
‘where do i write all of these queries to get the data I want?’. For this
you need to talk to your developers, if you are working for a decent
tech company then you might already have a read-only database
exposed for analytical usage, and that tool will most probably give you
a window to write custom SQL queries like the ones we have studied
above.
Some common free tools you can use to expose read-only databases
are:
● Redash
● Metabase
● PHPMyAdmin
● MYSQL WorkBench
● Heide SQL, etc.
© HELLOPM.CO
Here is how metabase looks like:
© HELLOPM.CO
● Do some sanity check on the output of your data, especially
when you are using joins. Take help from the data team when in
doubt.
● Ensure that your data analysis is correct before presenting it to
stakeholders, presenting wrong data is one sure shot way to
losing trust. Take help from data team and do sanity checks
[again].
● Learn about common functions around how to work with dates
in SQL. Dates are going to be an important part of your data
analysis process and they behave differently than other data
types. You can learn about common date functions here. Also,
keep in mind the time zone in which your database is recording
data.
There could be lots of such questions for your own product through
which you can practise your newly acquired SQL skills and build a
solid understanding of your data and customer experience.
© HELLOPM.CO
That’s all folks!
I hope this guide will help you make better and quicker decisions as a
product manager. Please share this guide with aspiring or existing
product managers in your circle, I am sure they are going to thank you
for this!
© HELLOPM.CO