Why SQL is Important for Marketers


sql-for-marketers-header
This is a guest post from Justin Mares, the co-author of the upcoming Traction Book. He formerly ran growth at Exceptional Cloud Services, before they were acquired by Rackspace in 2013. 

Today’s best marketers and growth hackers are data-driven. They are able to pull data about their marketing campaigns, and use that data to get a clear picture of what’s working (and what’s not).

A key component of being data-driven is the ability to quickly collect data. For pulling data from customer databases, there are few better tools out there than SQL, and none that are more popular.

SQL is a database language (Structured Query Language) that’s used to pull information from a database. Every action your customers take is captured in a customer database somewhere. Knowing how to use SQL allows you to retrieve just about any data you could ever want to know about your customers.

Imagine you had an Excel spreadsheet that contained every possible bit of data you have about your customers – what plans they’re on, how often they’ve bought from you, when they signed up, what marketing campaign they saw when they signed up, every action they’ve taken on your website or within your application… what could you do with that data?

Knowing SQL is basically like having access to such a spreadsheet.

You can use it to do cohort analysis and see if customers are using your product more or less over time, to analyze different marketing campaigns, to see what actions your most valuable users took, figure out the demographics of your most valuable customers and then create ad campaigns targeting similar demo..the list goes on.

These kinds of technical skills are only becoming more important as marketing becomes more data-driven. As Jamie Steven, former CMO of Moz mentioned:

“Regardless of whether or not you subscribe to these labels, technical skills are becoming a requirement for success in online marketing. The marketers who know SQL, can write code, leverage APIs, and perform quantitative analysis will be the most desirable and productive individuals in our industry.”

How does SQL work?

As we mentioned above, SQL allows you to find any data you want about your customers. Knowing how to use SQL is quite literally a marketing superpower.

Luckily, SQL is simple enough that you’ll be able to use it for any kind of data analysis, cohort analysis or campaign breakdown just by knowing a few key statements. Most tutorials online are meant for developers – for people who will be using SQL to manage databases and do things like drop tables, manipulate data, and other complex things. I’ll cover the basic queries most marketers will need to understand below.

**A word of caution: be sure to run these queries on a read-only or “slave database”. Running queries on a live production database can costly if it leads you to make an irreversible mistake, or have the effect of slowing down your site’s performance.**

Here’s what an example SQL query looks like. Can you guess what it’s doing?

sql-for-marketers

I’ll break this query down line by line to show you exactly what it’s doing. This query is based on the database in this W3schools example:

  1. This first part is telling our database what table (think of a table like an Excel spreadsheet) and what column to pull data from. In this case, it’s pulling from the “customerid” column of the “orders” table. The second part of this line is pulling data from the “customername” column of the “customers” table. Lastly, this statement is instructing SQL to count the occurrences of “customerid” in the “orders” table.
  2. This line is telling SQL where to pull data from. In this case, we’re telling SQL to pull data from the orders table
  3. This line is a bit more complex. It’s instructing SQL to temporarily join two tables we’d like to search, so that we can pull data from multiple queries. “Join” tells SQL which table we’d like to join, and the “on” modifier tells SQL which columns in those tables should map to each other. In this case, we’re pulling data from both the “customers” table and the “orders” table with one query.
  4. This line groups our information by “customerid”. This “group by” clause is useful because it tells SQL how we want to see the data returned, so that we can make sense of it.
  5. “Order by” determines how our returned data will be ordered. In this case, we’ll order the data

Try running this query in the linked W3 database and see what result is returned. Then, you’ll have written your first SQL query!

Wrap-up

I hope you are starting to see how SQL can be incredibly useful. Want to see how many customers have signed up in the past week? Write a SQL query. Curious how well your ads are performing? Easily accessible with a SQL query.

Hopefully this short tutorial has been a useful introduction to the basics of SQL. If you want to really dive in and become proficient, my SQL for Marketers course goes into a lot more depth. Use that link for 50% off the purchase price for the next two days.

Happy querying!




Get the latest discounts delivered straight to your inbox.