order_id | customer_id | product | price
1 | 101 | Laptop | 60000
2 | 102 | Phone | 30000
3 | 101 | Mouse | 1000
To retrieve order details:
SELECT
order_id,
customer_id,
product,
price
FROM orders;
To calculate price after adding a hypothetical 10% increase:
SELECT
product,
price,
price * 1.10 AS increased_price
FROM orders;
🔹 21. SELECT in Real-World Data Science
SQL is often the first step in a Data Science workflow.
For example:
Business Question
"Give me all customer transactions from the sales database."
You might start with:
SELECT
customer_id,
order_date,
product_id,
amount
FROM transactions;
Then later:
WHERE → Filter data
GROUP BY → Aggregate data
JOIN → Combine tables
ORDER BY → Sort results
Window Functions → Advanced analysis
Eventually, you may load the SQL result into Pandas:
import pandas as pd
df = pd.read_sql(query, connection)
So SQL and Python often work together.
🔹 22. Common Beginner Mistakes
❌ Mistake 1: Forgetting the FROM clause
Incorrect:
SELECT name;when you intend to retrieve a column from a table.
Correct:
SELECT name
FROM customers;
❌ Mistake 2: Using commas incorrectly
Correct:
SELECT name, city, age
FROM customers;
❌ Mistake 3: Confusing column names and values
A column:
cityis different from a text value:
'Pune'We'll explore this more when we learn WHERE.
❌ Mistake 4: Using SELECT * everywhere
SELECT * is useful while learning and exploring, but for production queries, selecting only the required columns can be more efficient and clearer.🔹 23. Interview Questions
💡 What does SELECT do?
SELECT specifies the columns or expressions that should appear in the query result.
💡 What does SELECT * mean?
It selects all columns from the specified table.
💡 What is an alias?
An alias gives a temporary name to a column or expression in the query result.
💡 What does DISTINCT do?
It removes duplicate rows from the selected result.
🎯 Practice Questions
Q1. Write a query to select all columns from a table called employees.
Q2. Write a query to select only employee_id and salary from employees.
Q3. Write a query to display salary as monthly_salary.
Q4. Write a query to calculate price * quantity as total_amount from an orders table.
Q5. Write a query to return unique values from the department column of an employees table.
🎯 Key Takeaways
✅ SQL is used to communicate with relational databases.
✅ SELECT specifies what you want to retrieve.
✅ FROM specifies the table.
✅
* means all columns.✅ You can select one or multiple columns.
✅ AS creates a temporary alias.
✅ SQL can perform calculations.
✅ DISTINCT returns unique results.
✅ SQL is one of the most important tools for extracting data before analysis and Machine Learning.
🧭 Double Tap ❤️ For More