SQL Basics for Data Analysts: A Beginner's Guide
By Vinay
Founder of Vtricks Technologies
Domain: Tech Education & Future Workforces • October 2025
Every data analyst's career starts with the same first step — writing a SELECT statement. SQL basics are simple enough that you can learn the syntax in an afternoon, but they are also the foundation of everything else you will do in analytics. Before you touch Tableau, Power BI, or Python, you need to be comfortable pulling data from a table, filtering it, sorting it, and returning exactly the rows a business question demands.
This guide walks you through the core SQL basics every data analyst needs — the commands that appear in nearly every query you will ever write. If you are considering a data analytics course in Bangalore, treat this as your primer. By the end, you will understand what each command does, when to use it, and how to combine them into queries that answer real questions. For a deeper dive into analytical techniques, check out our complete SQL for data analytics guide.
What Is a SQL Query, Really
A SQL query is a sentence you write to ask a database a question. The database reads your sentence, finds the matching data, and returns it as a table. That is all. Every SQL query, from a one-line lookup to a 200-line analytical monster, follows the same basic grammar: SELECT what you want, FROM where, WHERE these conditions are true, GROUP BY these categories, HAVING these group conditions, ORDER BY this column, LIMIT to this many rows.
You will not use every clause in every query. But the order is fixed, and understanding this order is half the battle. Beginners who skip this step end up guessing where to put WHERE versus HAVING, and their queries either error out or return wrong numbers.
The SELECT Statement: Your First Query
SELECT is how you tell the database which columns you want. The simplest possible query is:
SELECT * FROM customers;
The asterisk means "every column." In production, you rarely use SELECT * because it wastes bandwidth and hides which columns your query actually depends on. A better version names the columns:
SELECT customer_id, name, email, city FROM customers;
You can also compute new columns in the SELECT clause. If your table has first_name and last_name, you can create a full name on the fly:
SELECT customer_id, first_name || ' ' || last_name AS full_name, email FROM customers;
The AS keyword renames the output column. Analysts use aliases constantly to make results readable. Any good data analytics course in Bangalore will drill this habit early, because clean, well-aliased output is what separates a report an executive can read from one they cannot.
Filtering with WHERE
The WHERE clause narrows the rows the database returns. It comes right after FROM and before GROUP BY:
SELECT customer_id, name, city FROM customers WHERE city = 'Bangalore';
WHERE supports the operators you would expect: =, !=, <, >, <=, >=. It also supports logical combinations with AND, OR, and NOT:
SELECT * FROM orders WHERE amount > 1000 AND status = 'completed';
For a list of possible values, IN is cleaner than a chain of ORs:
SELECT * FROM customers WHERE city IN ('Bangalore', 'Mumbai', 'Delhi');
For ranges, BETWEEN is readable:
SELECT * FROM orders WHERE order_date BETWEEN '2025-01-01' AND '2025-03-31';
For pattern matching, LIKE with wildcards (% for any string, _ for any single character):
SELECT * FROM customers WHERE email LIKE '%@gmail.com';
Finally, for missing values, use IS NULL or IS NOT NULL — never = NULL, which does not work as beginners expect.
Sorting with ORDER BY
ORDER BY sorts the result. By default it sorts ascending; add DESC for descending:
SELECT customer_id, name, total_spent FROM customers ORDER BY total_spent DESC;
You can sort by multiple columns. The database sorts by the first, and uses the second as a tiebreaker:
SELECT * FROM orders ORDER BY order_date DESC, amount DESC;
You can also sort by a column position number, though this is discouraged in production because it breaks when columns move:
SELECT customer_id, name, total_spent FROM customers ORDER BY 3 DESC;
ORDER BY happens after WHERE and GROUP BY, which is why you can sort by aggregated columns like SUM(amount).
Limiting Results with LIMIT
LIMIT returns only the first N rows. It is essential for exploring large tables without pulling millions of rows into your session:
SELECT * FROM orders ORDER BY order_date DESC LIMIT 10;
This returns the 10 most recent orders. LIMIT combined with ORDER BY is the standard "top N" pattern — top 10 customers by revenue, top 5 products by units sold, most recent 100 signups.
Some dialects use TOP instead of LIMIT (SQL Server) or ROWNUM (older Oracle). LIMIT works in MySQL, PostgreSQL, SQLite, BigQuery, and Snowflake, which covers what you will meet in most data analyst roles in Bangalore.
Getting Unique Values with DISTINCT
DISTINCT removes duplicate rows from the result. It is one of the most-used commands during data exploration:
SELECT DISTINCT city FROM customers;
This returns each city exactly once. It is your quick way to answer "what values does this column contain?" You can also use DISTINCT across multiple columns to find unique combinations:
SELECT DISTINCT city, country FROM customers;
Beware: DISTINCT is not free. On large tables it forces the database to sort and deduplicate the entire result set, which can be slow. If you need distinct counts, COUNT(DISTINCT column) is often what you actually want:
SELECT COUNT(DISTINCT customer_id) FROM orders;
This tells you how many unique customers placed at least one order — a much more useful business metric than raw row counts.
Putting It Together: A Realistic Query
Let's write a query that answers a real business question: "What are the top 10 customers in Bangalore by total spend in the first quarter of 2026?"
SELECT customer_id, name, SUM(amount) AS total_spent
FROM orders
WHERE city = 'Bangalore'
AND order_date BETWEEN '2026-01-01' AND '2026-03-31'
AND status = 'completed'
GROUP BY customer_id, name
ORDER BY total_spent DESC
LIMIT 10;
This query uses SELECT to pick columns, WHERE to filter, GROUP BY to aggregate, an aggregate function (SUM), ORDER BY to sort, and LIMIT to cap the result. This is the shape of nearly every analytical query you will ever write. Master this pattern and you have already covered most of the SQL that appears in a beginner-level data analytics course in Bangalore.
Common Mistakes Beginners Make
Three mistakes trip up almost every new SQL learner.
Forgetting that WHERE runs before GROUP BY. You cannot filter on an aggregate in WHERE. If you want to filter groups, use HAVING. WHERE filters rows, HAVING filters groups. This is the number one interview trap.
Confusing = NULL with IS NULL. NULL is not equal to anything, including itself. Always use IS NULL and IS NOT NULL.
Using SELECT * in production queries. It is fine for exploration, but never in a query that feeds a dashboard. When the underlying table gains a column, your report silently changes.
Building the habit of clean, explicit queries from day one is what a good data analytics course in Bangalore will emphasize, and it will save you months of debugging later in your career.
How to Practice SQL Basics
You do not learn SQL by reading — you learn it by writing queries against real data. Set up a free MySQL or PostgreSQL sandbox on your laptop, or use browser tools like SQLZoo, Mode Analytics tutorials, or LeetCode's SQL section.
Download a public dataset — the Sakila movie rental database, the Chinook music store database, or any dataset from Kaggle — and start writing queries to answer questions you invent. "Which month had the highest revenue?" "Which city has the most repeat customers?" "What is the average order value by product category?" Every question you can answer is a rep of SQL fluency.
Aim for 30 minutes of hands-on SQL every day for a month. That is roughly the point at which the syntax stops feeling foreign and starts feeling like a natural way to think about data. From there, SQL joins explained, subqueries, and window functions become natural next steps — and you are ready for the harder material that any credible data analytics course in Bangalore will throw at you.
Final Thoughts
SQL basics look deceptively simple, and that is a good thing — it means you can start writing useful queries in your first week. The depth comes later, with joins, aggregations, and window functions. But everything is built on this foundation: SELECT the columns you want, FROM the right table, WHERE the conditions filter down to the rows that matter, ORDER BY the column that answers the question, LIMIT the noise. Every senior data analyst you will ever work with started here. Get comfortable with these basics, and every advanced concept becomes an incremental step rather than a leap.