Categories
Analysis Analytics Business Tips

5 SQL Queries Every Analyst Should Know

SQL is one of the most important tools in any analyst’s toolkit. Whether you’re pulling transactional sales data, cleaning messy records, or preparing insights for dashboards, SQL is often the very first step.

If you’re just getting started, here are the five SQL queries that will cover 80% of your daily work as an analyst.


SELECT

The Foundation

This is your bread and butter: pulling data from a table.

Think of SELECT as your “give me the data” query. It’s the most basic — and the most powerful — command in SQL.

CODE SNIPPET:


WHERE

Filtering Results

Analysts rarely want all the data. WHERE lets you focus on what matters.

CODE SNIPPET:

For example, the query above pulls only shipped orders after January 1, 2025. Trust me, this is especially important when you’re working with millions of records that go back years. You do not want to be poring over a list that seems infinite and neither does the recipient who may have requested the ad-hoc report from you.

WHERE can be used to filter by categories or conditions as well.


GROUP BY

Summarizing Data

Aggregation is where insights begin. GROUP BY helps you summarize large datasets.

CODE SNIPPET:

Now you can see which products have the most orders. Perfect for identifying bestsellers or analyzing trends.


JOIN

Combining Tables

Most real-world data lives in multiple tables. JOIN lets you stitch it together.

CODE SNIPPET:

This connects customer details with their order history. Almost every analytics project requires joins at some point.

JOIN is often the most confusing query that beginners come across since there are different types. It can get confusing but don’t let that intimidate you, I’ll cover the different types of joins in a separate post 🙂


CASE

Adding Logic to Queries

Sometimes you need to create quick categories without exporting to Excel or Python. That’s where CASE comes in.

CODE SNIPPET:

This example creates a new column that classifies orders as “High Value” or “Standard.”

WRAPPING UP

These five SQL queries are the building blocks of data analysis. Master them, and you’ll unlock the ability to:

  • Extract exactly the data you need
  • Summarize and explore patterns
  • Connect multiple sources together
  • Add quick insights directly in SQL

Once you’re comfortable with these basics, you’ll be ready for more advanced techniques like CTEs, window functions, and query optimization.

Ardonna •ᴗ•

Ardonna Cardines Avatar

Leave a Reply

Discover more from Mercury Musings

Subscribe now to keep reading and get access to the full archive.

Continue reading