SQL Basics — SELECT, FROM, WHERE
Every SQL interview starts here. These are the most common questions asked at every level — fresher to senior. Master these before anything else.
What is SQL and why is it used in data analytics?
SQL (Structured Query Language) is used to query and manipulate data stored in relational databases.Data analysts use SQL daily to extract insights from databases — filtering sales data, aggregating customer records, joining multiple tables to answer business questions.
Write a query to select all columns from a table called "employees".
SELECT * FROM employees;The * wildcard selects all columns. In production, always name specific columns instead of * for better performance and clarity.
How do you filter rows where salary is greater than 50000?
SELECT * FROM employees
WHERE salary > 50000;WHERE filters rows before they are returned. Common operators: >, <, >=, <=, =, != (or <>).
Select employees from the "Sales" department only.
SELECT * FROM employees
WHERE department = 'Sales';String values in WHERE must use single quotes. SQL is case-insensitive for keywords but case-sensitive for string values depending on the database.
How do you combine two conditions — salary > 40000 AND department = "HR"?
SELECT * FROM employees
WHERE salary > 40000
AND department = 'HR';AND requires both conditions to be true. OR requires at least one. Use parentheses when combining AND/OR to control precedence.
What is the difference between WHERE and HAVING?
-- WHERE filters individual rows BEFORE grouping:
SELECT department, COUNT(*)
FROM employees
WHERE salary > 30000
GROUP BY department;
-- HAVING filters groups AFTER grouping:
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;WHERE cannot reference aggregate functions (COUNT, SUM, etc.) because it runs before GROUP BY. HAVING runs after GROUP BY and can filter on aggregates.
EVIKA ACADEMY · SQL FOR DATA ANALYTICS
Want to master SQL with live practice?
Join our SQL for Data Analytics course — live classes in Noida and online across India.
Book Free Demo Class →