It is impossible to create any model or graph before having the necessary information. All the information is stored in the database. To request this information, we make use of SQL. In a Data Science Course in Pune Online, one finds SQL everywhere. This skill set is always tested during an interview round. So here are some queries you should learn first.
Why SQL Matters in Data Science
Data Scientists need to spend lots of time extracting, processing, and analyzing data prior to creating models from data. All these tasks can be done easily using SQL, which works fast even when processing millions of lines of data at once. Both Python and Excel tools help, but data needs to reach these platforms first through SQL.
In these examples, we have used two very basic tables named customers(id, name, city) and orders(id, customer_id, amount, order_date).
1. SELECT: Choose What You Want to See
SELECT picks the columns you need.
SELECT name, city FROM customers;
Use SELECT * only for a quick look. On large tables, ask for specific columns so queries run faster.
2. WHERE: Filter Your Data
WHERE keeps only the rows that match a condition.
SELECT * FROM orders WHERE amount > 500;
You can combine conditions with AND, OR, and IN, such as WHERE city IN ('Pune', 'Delhi').
3. ORDER BY and LIMIT: Sort and Preview
ORDER BY sorts results, and LIMIT keeps the output short.
SELECT * FROM orders ORDER BY amount DESC LIMIT 10;
It will give you the ten biggest orders. Also, there's another keyword named TOP used by some other databases instead of LIMIT.
4. Aggregate Functions: Summarize Quickly
These functions turn many rows into one answer:
COUNT() counts rows
SUM() adds values
AVG() finds the average
MIN() and MAX() find the smallest and largest values
SELECT COUNT(*), AVG(amount) FROM orders;
5. GROUP BY: Summarize by Category
GROUP BY splits data into groups and applies a function to each one.
SELECT customer_id, SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id;
It is commonly used in practical scenarios. For example, "sales per city" or "orders per month."
6. HAVING: Filter Groups
WHERE filters rows before grouping. HAVING filters the groups after.
SELECT customer_id, SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id
HAVING SUM(amount) > 5000;
7. JOIN: Combine Tables
Real data is spread across tables. JOIN connects them using a shared column.
SELECT c.name, o.amount
FROM customers c
JOIN orders o ON c.id = o.customer_id;
Start with INNER JOIN, which gives us all matching rows. Afterward comes the LEFT JOIN, which will include all rows in the first table regardless of whether or not they have matches. The join concept is the hardest thing newbies struggle with, and hence we should master it.
8. DISTINCT and NULL: Clean Your Data
DISTINCT removes duplicates:
SELECT DISTINCT city FROM customers;
Missing values appear as NULL. Check for them with IS NULL, not = NULL:
SELECT * FROM customers WHERE city IS NULL;
9. Subqueries: A Query Inside a Query
A subquery lets you use one result inside another.
SELECT * FROM orders
WHERE amount > (SELECT AVG(amount) FROM orders);
This returns orders above the average amount.
How to Practice SQL
Write each query yourself instead of copying it.
Use free practice platforms or a small sample database.
Work with real datasets, such as sales or survey data.
Explain each query in plain words to check your understanding.
Try sticking to daily training sessions of around 30 minutes each day. Once you get used to these nine questions, go ahead and learn about window functions and CTEs (Common Table Expressions).
Conclusion
SQL is one of those languages that has few keywords but delivers great power. Once you learn SELECT, WHERE, GROUP BY, JOIN, and subqueries, you will find yourself answering almost all queries related to beginner-level problems.
If you are interested in guided learning, you could try out Data Science Training in Gurgaon to enhance your knowledge of SQL along with Python, Statistics, and Machine Learning.