Learn SQL from fundamentals to advanced interview and
production-level database concepts through practical examples,
questions and quizzes.
Complete SQL Learning & Interview Path
Learn SQL by working with realistic databases instead of
memorising isolated commands. Every concept can be connected
with practical tables such as students, employees,
departments, countries, states, customers, products and orders.
SQL is used to store, retrieve, modify and analyse structured
data. Instead of learning commands independently, imagine that
we are building a small company database.
Student table
A student database can contain identity, name,
course and marks.
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(100),
course VARCHAR(100),
marks INT
);
Employee table
Employee information can be connected with departments,
salaries and managers.
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(100),
department_id INT,
salary DECIMAL(12,2)
);
Country / State table
Geographic data is useful for understanding
relationships and JOINs.
CREATE TABLE states (
id INT PRIMARY KEY,
name VARCHAR(100),
country_id INT
);
Customer / Orders
E-commerce data provides practical examples for
aggregation, JOINs and transactions.
CREATE TABLE orders (
id INT PRIMARY KEY,
customer_id INT,
total DECIMAL(12,2),
order_date DATE
);
id
name
course
marks
1
Rahul
Java
85
2
Priya
SQL
92
3
Amit
React
76
SQL Learning Block 1
Questions
1
–
10
1
Question
1
of 10
What is SQL?
Solution
SQL (Structured Query Language) creates, reads, updates and deletes relational data; it also supports joins, aggregation, transactions and permissions.
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
2
of 10
What are DDL, DML, DQL, DCL and TCL?
Solution
DDL: CREATE, ALTER, DROP, TRUNCATE.
DML: INSERT, UPDATE, DELETE.
DQL: SELECT.
DCL: GRANT, REVOKE.
TCL: COMMIT, ROLLBACK, SAVEPOINT.
SELECT * FROM employees;
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
3
of 10
How do you retrieve all employees?
Solution
SELECT *
FROM employees;
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
4
of 10
How do you retrieve specific columns?
Solution
SELECT id, name, salary
FROM employees;
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
5
of 10
How do you find employees earning more than 50,000?
Solution
SELECT * FROM employees
WHERE salary > 50000;
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
6
of 10
How do you find employees earning between 30,000 and 70,000?
Solution
SELECT * FROM employees
WHERE salary BETWEEN 30000 AND 70000;
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
7
of 10
How do you find employees from specific departments?
Solution
SELECT * FROM employees
WHERE department_id IN (1, 2, 3);
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
8
of 10
How do you find employees whose name starts with 'A'?
Solution
SELECT * FROM employees WHERE name LIKE 'A%';
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
9
of 10
How do you find names ending with 'n'?
Solution
SELECT * FROM employees WHERE name LIKE '%n';
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Question
10
of 10
How do you find names containing 'an'?
Solution
SELECT * FROM employees WHERE name LIKE '%an%';
Think before looking at the solution
What would the SQL query do?
Which rows will match?
Which columns will appear?
What happens when NULL values are involved?
Can the query be improved using an index?
Knowledge Check
Quiz after Questions
1
–
10
Test yourself before moving to the next SQL
learning block.
1.
What is SQL?
2.
What are DDL, DML, DQL, DCL and TCL?
3.
How do you retrieve all employees?
4.
How do you retrieve specific columns?
5.
How do you find employees earning more than 50,000?
6.
How do you find employees earning between 30,000 and 70,000?
7.
How do you find employees from specific departments?
8.
How do you find employees whose name starts with 'A'?