Back to articles list Articles Cookbook
8 minutes read

SQL Queries You'll Actually Use in Real Life

Learn the essential SQL queries that data analysts, marketers, and product teams rely on every day – with simple, relatable examples.

When you're just starting with SQL, it's easy to get overwhelmed by syntax and theory. But here’s the truth: most professionals – whether they’re data analysts, marketers, or product managers – use a small set of SQL queries over and over to get real work done. You don’t need to learn everything at once.

This article walks you through the essential SQL queries that beginners actually use on the job. No abstract data or complicated math – just clear, beginner-friendly examples you can understand and apply right away.

Let’s imagine you're working with an online bookstore’s database. You want to analyze the orders and customers tables to answer everyday business questions.

To learn SQL step by step – with hands-on exercises and real-world examples – go to our SQL Basics course. It’s everything you need to build a strong foundation. The course includes 129 interactive exercises, all focused on practical, hands-on learning. You’ll write real SQL code from the start, get instant feedback, and build the confidence to use SQL in your daily work.

Let’s start with the queries!

1. Look at a Sample of the Data

The first query you’ll run in almost any database is a quick look at the data itself. You want to see what kind of information you're working with. 

SELECT * 
FROM orders
LIMIT 10;

This query selects all columns but only shows the first 10 rows. It gives you a quick peek at the structure of the orders table – including columns like order_id, customer_id, order_date, and total_amount. It’s a simple way to get familiar with your dataset before you start analyzing. It’s important not to select all rows from the table, especially in large datasets, as this can overwhelm the database. Selecting just 10 or 20 rows is a safe way to preview the data.

2. Know the Size of Your Table

The next query you’ll typically run is to find out how many rows are in a table:

SELECT COUNT(*) 
FROM orders;

This tells you how many orders your business has in total. It’s a good idea to run this for all the tables you plan to work with, so you know how large each one is before diving into analysis.

3. See all Unique Values in a Column

Next, you’ll want to check all the unique values in a column – especially for “dictionary” columns like city names, product categories, or payment methods. These are columns where each value represents a label, type, or category, and understanding what’s in there helps you make better decisions during analysis.

For example, to see all the different payment methods used:

SELECT DISTINCT payment_method 
FROM orders;

The DISTINCT keyword removes duplicates from the results. Instead of showing every row’s value, it only returns each unique value once. So if "credit_card" appears 5,000 times in the table, it will only appear once in the result.

This is useful when you want to:

  • Check the full list of available options in a column.
  • Understand how values are categorized.
  • Prepare for filtering, grouping, or cleaning your data.

You can use DISTINCT with any column to quickly explore the variety of values it contains.

4. Count how Often Each Value Appears

This is one of the most commonly used queries in real life. It helps you see the distribution of values in a column – especially in “dictionary” columns like payment_method, category, or city.

Say you want to know how many orders were placed using each payment method:

SELECT payment_method, COUNT(*) AS num_orders
FROM orders
GROUP BY payment_method;

This query groups the rows by payment_method and then counts how many rows (i.e., orders) fall into each group. The result shows each payment method along with the number of orders that used it.

Use this pattern whenever you want to break down your data by category – for example, to see how many orders came from each city or how many products fall into each category.

To make the results easier to read, you can sort them by frequency (highest to lowest):

SELECT payment_method, COUNT(*) AS num_orders
FROM orders
GROUP BY payment_method
ORDER BY COUNT(*) DESC;

This helps you quickly see which values are the most common.

5. Find Minimum, Maximum, and Average Values

Next, you’ll want to see the range of values in a numeric column. This helps you understand things like order size, pricing, or quantity.

For example, to check the smallest, biggest, and average order amounts:

SELECT 
  MIN(total_amount) AS smallest_order,
  MAX(total_amount) AS biggest_order,
  AVG(total_amount) AS average_order
FROM orders;

This query uses three aggregate functions:

  • MIN finds the smallest value.
  • MAX finds the largest value.
  • AVG calculates the average.

It gives you a quick overview of the spread of values in the total_amount column – useful for spotting outliers or setting thresholds for further analysis.

Bonus: You can break down the range by category using GROUP BY. For example, to see the minimum, maximum, and average order amount by payment method:

SELECT  
  payment_method,  
  MIN(total_amount) AS smallest_order,  
  MAX(total_amount) AS biggest_order,  
  AVG(total_amount) AS average_order  
FROM orders  
GROUP BY payment_method;

This lets you compare how different categories perform – like which payment method tends to have higher or lower order amounts.

6. Filter Rows With WHERE

Sometimes you don’t need the whole table – just the rows that meet specific conditions.

For example, to see only the orders over $100:

SELECT *
FROM orders
WHERE total_amount > 100;

This is how you focus on high-value orders – great for spotting big spenders or identifying potential VIP customers.

You can also combine multiple conditions using AND:

SELECT *
FROM orders
WHERE total_amount > 100
  AND payment_method = 'credit_card';

Now you’re filtering for customers who spent over $100 and paid with a credit card – maybe these are your most valuable users.

Filtering with WHERE is one of the most useful things you’ll do in SQL. It helps you answer targeted business questions, like:

  • Who made large purchases?
  • Who used a specific payment method?
  • Which orders happened after a certain date?

You can also use OR, IN, NOT, and other operators to customize your filters even more – but WHERE is the starting point for almost any data deep dive.

7. Sort Your Data With ORDER BY

Want to see the highest value orders first? You can sort your results using ORDER BY and control the direction with DESC (for descending) or ASC (for ascending):

SELECT *  
FROM orders  
ORDER BY total_amount DESC  
LIMIT 10;

This shows the top 10 biggest orders ever placed – sorted from highest to lowest by total_amount.

This kind of query is great for all kinds of sorting tasks, such as:

  • Finding the top or bottom results based on any column.
  • Ranking items by sales, quantity, or performance.
  • Spotting trends by ordering data over time.
  • Highlighting outliers or unusual values.

If you want to see the smallest orders instead, just change DESC to ASC:

…
ORDER BY total_amount ASC

Pro tip: You can sort by any column – not just numbers. For example, sorting by order_date shows the newest or oldest orders, depending on the sort direction.

8. Combine Tables With JOIN

One of the most common queries you’ll use in real life is a JOIN. That’s because useful information is often spread across multiple tables. You’ll constantly need to combine them to get the full picture.

For example, the orders table only stores the customer_id, not the customer’s actual name. To see each order along with the name of the person who placed it, you need to join it with the customers table:

SELECT  
  o.order_id,  
  c.customer_name,  
  o.total_amount,  
  o.order_date  
FROM orders o  
JOIN customers c ON o.customer_id = c.customer_id;

This query connects the two tables using the customer_id column, which exists in both. We use table aliases (o for orders, c for customers) to make the query easier to read.

The result? A much more useful dataset. Now you can see who placed each order, how much they spent, and when – which is essential for customer analysis, reporting, and business insights.

JOINs are everywhere. Anytime you work with real databases, you'll be joining tables – whether it's orders and customers, products and categories, or users and activity logs.

9. Filter by a Date Range

One of the most common real-life tasks is filtering data for a specific time period – like showing all orders from a given month or quarter.

Let’s say you want to see all orders placed in May 2024:

SELECT *  
FROM orders  
WHERE order_date >= '2025-05-01'  
  AND order_date < '2025-06-01';

This returns all orders where order_date falls between May 1 and May 31, 2025 – inclusive of May 1 and up to (but not including) June 1.

The date format used here is YYYY-MM-DD:

  • YYYY = 4-digit year (e.g. 2024)
  • MM = 2-digit month (e.g. 05 for May)
  • DD = 2-digit day (e.g. 01 for the 1st of the month)

Using < '2024-06-01' instead of <= '2024-05-31' is safer when your column includes time values, like '2024-05-31 15:42:00', because it avoids accidentally excluding data from the last day.

Final Tip: Practice on Realistic Data

The best way to remember these queries is to use them. Practice with data that makes sense to you – like customer orders, blog traffic, or app usage. SQL doesn’t have to be overwhelming. You don’t need hundreds of commands to do real work – just a small set of practical queries you can rely on every day.

To build real confidence and muscle memory, try the SQL Basics course at LearnSQL.com. It gives you hands-on practice with realistic datasets and 129 interactive exercises – so you learn by writing actual SQL, not just reading about it.

Start with the basics above – and you’ll be surprised how far they can take you.