SQL for the SQL-Curious: Learn the Language of Databases in a Fun Way!

Kate Strachnyi
6 min readJan 15, 2023

--

If you are not familiar with SQL — Structured Query Language, AND you are curious about learning more — then this article is for YOU!

We’re going to make learning SQL as fun and easy as a walk in the park!

Photo by Kevin Gent on Unsplash

So grab your thinking cap, and let’s start our journey of going from SQL-Curious to SQL-Expert! Okay maybe not EXPERT, but you’ll at least know what people are talking about when they say SQL!

SQL for ULTRA- Beginners

SQL, or Structured Query Language, is a powerful tool used to manage and manipulate data in relational databases. It’s the language of databases and it’s like the “glue” that holds all your data together. Think of it like a magical spell that allows you to organize, filter, and extract insights from your data.

But why is SQL so important? Well, for starters, it’s used everywhere! From big corporations to small startups, SQL is an essential tool for data analysis and business intelligence. It allows you to make data-driven decisions, which is crucial for the success of any business.

But it’s not just for businesses, SQL is also used by researchers, data scientists, and even journalists to extract insights from data. It’s like a secret weapon for anyone working with data. And the best part is, it’s not as hard as you may think. With the right tools and resources, anyone can learn SQL!

But what exactly can you do with SQL? The possibilities are endless! With SQL, you can:

  • Organize and structure your data in tables
  • Filter and extract specific data with just a few lines of code
  • Join tables together to extract insights
  • Aggregate data and make calculations
  • Create and modify tables and databases

And that’s just the tip of the iceberg! SQL is like a superpower for data management and the more you learn, the more you can do.

Example: You’re a detective in a crime TV show

Congratulations! You are now a DETECTIVE in a crime TV show- and you have a job to do.

Photo by Edo Nugroho on Unsplash

Your task? you have to solve a mystery. But instead of a pile of clues, you’ve got a huge amount of data that you need to sift through. Now, without SQL, it would be like trying to find a needle in a haystack, but with SQL, it’s like having a magical magnifying glass that helps you zoom in on the clues you need to solve the case.

Photo by Marten Newhall on Unsplash

For example, let’s say you have a table of suspects, each with their name, age, address, and alibis. With SQL, you can easily filter out suspects based on certain criteria. For example, you can use the WHERE clause to only show suspects who are between the ages of 25 and 35 and who have an alibi that is “unverified”.

SELECT name FROM suspects
WHERE age BETWEEN 25 AND 35
AND alibi = 'unverified';

Now, let’s say you also have a table of evidence, with the item, location, and a suspect_id linking it to the suspects table. With SQL, you can use a JOIN clause to combine the two tables and see which suspect is linked to which piece of evidence.

SELECT suspects.name, evidence.item
FROM suspects
JOIN evidence
ON suspects.suspect_id = evidence.suspect_id;

See how easy it is to extract the data you need to solve the case? With SQL, you can filter, join and extract insights from your data in a matter of seconds. It’s like having a superpower for data management and it’s a game-changer for solving any mystery.

So, whether you’re a detective trying to solve a crime or a data analyst trying to extract insights from your data, SQL is an essential tool to have in your toolbox.

Speak the Language

You noticed in the code above, we referenced some words like WHERE, JOIN, SELECT, etc. What do these words mean?

WHERE Clause: The WHERE clause is used to filter data from a table. It allows you to specify conditions that rows must meet in order to be included in a query. For example, let’s say you have a table of customers and you want to find all the customers who live in California. You can use the WHERE clause to filter the data like this:

SELECT * FROM customers
WHERE state = 'California';

This query will only show the customers who live in California.

JOIN Clause: The JOIN clause is used to combine data from two or more tables. It allows you to link tables together based on a common field. For example, let’s say you have a table of customers and a table of orders. You want to see which customers have placed orders. You can use the JOIN clause to link the tables like this:

SELECT customers.name, orders.order_date
FROM customers
JOIN orders
ON customers.customer_id = orders.customer_id;

This query will show the name of the customers and the date of their orders.

IF THEN Clause: The IF THEN clause is used to make decisions in SQL. It allows you to test a condition and take different actions based on the result. For example, let’s say you have a table of products and you want to know which products are out of stock. You can use the IF THEN clause like this:

SELECT product_name,
CASE
WHEN stock = 0 THEN 'Out of Stock'
ELSE 'In Stock'
END AS stock_status
FROM products;

This query will show the name of the products and whether they are in stock or out of stock.

ELSE Clause: The ELSE clause is used in conjunction with the IF THEN clause. It’s used to specify an action that should be taken if the conditions in the IF THEN clause are not met. For example, let’s say you have a table of products and you want to know which products are out of stock or almost out of stock (less than 5 in stock). You can use the IF THEN ELSE clause like this:

SELECT product_name,
CASE
WHEN stock = 0 THEN 'Out of Stock'
WHEN stock < 5 THEN 'Low Stock'
ELSE 'In Stock'
END AS stock_status
FROM products;

This query will show the name of the products and whether they are in stock, low stock, or out of stock.

By using these clauses, you can filter, join, make decisions and extract insights from your data. Remember, the key to understanding SQL is practice, so don’t hesitate to try these clauses on your own using a SQL sandboxing tool or a sample database. And always try to use examples that are relatable to you, it will make it much easier to understand.

Practice Makes Perfect — or at least gets you further ahead than you were before

Now that you’re familiar with some common terminology and the LOGIC behind SQL, it’s a good idea to get your hands dirty and practice the skill.

Here are 5 methods that you can use to practice:

  1. Use a SQL sandboxing tool: These tools provide a user-friendly interface that allows you to write and execute SQL queries against a sample database. Some popular SQL sandboxing tools include SQLFiddle, DB-Fiddle, and SQLiteOnline.
  2. Practice on a sample database: Try out the Northwind database, which is widely used for SQL tutorials. It contains sample data for a fictional company, including tables for products, customers, orders, and more.
  3. Participate in online coding challenges: Competitions, such as HackerRank, Codewars and Leetcode have SQL sections where you can practice writing SQL queries.
  4. Use SQL in your projects: Incorporate SQL into your personal projects and practice retrieving data, filtering, and manipulating it. This one is MY FAVORITE way to learn — because you’re using data that you actually care about and understand.
  5. Get a hands-on experience: Look for internships or entry-level jobs that involve SQL to get real-world experience working with databases. It’s a great way to apply your skills and learn new ones while working with a team. If you’re working in a company, ask if you can shadow or help someone with their SQL work.

I wish you the best on your SQL — learning journey. Hopefully we’ve taken you away from being SQL-Curious and closer to knowing how to leverage the power of SQL in your data projects.

--

--

Kate Strachnyi
Kate Strachnyi

Written by Kate Strachnyi

Founder of DATAcated | Author | Ultra-Runner | Mom of 2

No responses yet