10 SQL Examples Every Corporate Professional Should Know
You don’t need to be a data engineer to use SQL. If you work with dashboards, reports, or any database-backed system, these ten queries cover almost everything you’ll need day to day. Examples use standard SQL syntax that works across most platforms (SQL Server, PostgreSQL, MySQL, Snowflake, etc.).
1. Basic filtering: SELECT and WHERE
Pull only the rows you care about.
SELECT customer_name, region, revenue
FROM sales
WHERE region = 'West' AND revenue > 10000;
Use this whenever you need a slice of a table instead of the whole thing — e.g., “show me only West region deals over $10K.”
2. Sorting results: ORDER BY
SELECT customer_name, revenue
FROM sales
ORDER BY revenue DESC;
Add LIMIT 10 (or TOP 10 in SQL Server) to get a top-10 list, like your biggest accounts or highest-value deals.
3. Summarizing data: GROUP BY with aggregates
SELECT region, SUM(revenue) AS total_revenue, COUNT(*) AS num_deals
FROM sales
GROUP BY region;
This is the workhorse of business reporting — total revenue by region, headcount by department, orders by month.
4. Filtering aggregated results: HAVING
SELECT region, SUM(revenue) AS total_revenue
FROM sales
GROUP BY region
HAVING SUM(revenue) > 500000;
WHERE filters rows before grouping; HAVING filters groups after. Use this when your condition depends on a sum, count, or average.
5. Combining tables: JOIN
SELECT o.order_id, c.customer_name, o.order_date, o.amount
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id;
Most real data lives in separate tables (orders here, customer details there). A JOIN links them by a shared key so you can report on both together.
6. Including unmatched rows: LEFT JOIN
SELECT c.customer_name, o.order_id
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
A regular JOIN only keeps matches. LEFT JOIN keeps every row from the first table, even with no match — useful for finding customers who never placed an order.
7. Counting unique values: COUNT(DISTINCT …)
SELECT COUNT(DISTINCT customer_id) AS unique_customers
FROM orders;
Answers “how many distinct customers” rather than “how many order rows,” which is a common mix-up in reporting.
8. Conditional logic: CASE WHEN
SELECT customer_name, revenue,
CASE
WHEN revenue > 100000 THEN 'Enterprise'
WHEN revenue > 10000 THEN 'Mid-Market'
ELSE 'SMB'
END AS segment
FROM sales;
CASE WHEN is SQL’s version of an IF/ELSE statement — handy for bucketing customers, flagging statuses, or recoding messy categories.
9. Date filtering for periods
SELECT customer_name, order_date, amount
FROM orders
WHERE order_date >= '2026-01-01' AND order_date < '2026-04-01';
Almost every business question is time-bound (“this quarter,” “last 30 days”). Getting comfortable with date ranges saves you from exporting full tables to Excel just to filter dates there.
10. Ranking within groups: Window functions
SELECT region, customer_name, revenue,
RANK() OVER (PARTITION BY region ORDER BY revenue DESC) AS rank_in_region
FROM sales;
This finds the top customer in each region without writing a separate query per region. Window functions (RANK, ROW_NUMBER, SUM() OVER) are the step up from basic GROUP BY once you need running totals or per-group rankings.
Tip: these ten patterns combine. A typical business question — “top 5 customers by revenue this quarter, by region” — is just #5, #6, #9, and #10 stacked together. Once these feel natural, you can answer most ad hoc data requests without waiting on a data team.
