SQL EssentialsQueries, Joins & Interview Questions
Free SQL revision course covering MySQL and ANSI SQL: SELECT, filtering, joins, subqueries, aggregates, functions and query practice.
Your Learning Progress
Module 1 – SQL Fundamentals
SQL Fundamentals
- SQL stands for Structured Query Language.
- SQL is used to communicate with relational database systems.
- SQL can be used to:
- Create databases.
- Create tables.
- Insert data.
- Retrieve data.
- Update data.
- Delete data.
- Control permissions.
- Manage transactions.
- SQL is declarative.
- In declarative programming, the programmer specifies what result is required rather than every implementation step.
- The database optimizer decides an efficient execution plan.
- SQL is standardized by ANSI and ISO.
- MySQL supports standard SQL plus MySQL-specific features.
- ANSI SQL refers to SQL features standardized across database systems.
- SQL keywords are generally written in uppercase for readability.
- SQL statements generally end with a semicolon.
- A database contains tables, views, indexes, procedures, functions, and other objects.
- A table contains rows and columns.
- A row is also called a record or tuple.
- A column is also called an attribute or field.
- A database schema defines the structure of database objects.
- A database instance represents the data stored at a particular moment.
- A NULL value represents missing, unknown, or inapplicable data.
- NULL is not the same as zero.
- NULL is not the same as an empty string.
- SQL uses three-valued logic:
- TRUE.
- FALSE.
- UNKNOWN.
- Any comparison with NULL normally produces UNKNOWN.
- Use IS NULL to check for NULL.
- Use IS NOT NULL to check for a non-NULL value.
- SQL comments can be written using --.
1-- This is a single-line comment226. MySQL also supports block comments.1/* This is2 a block comment */327. SQL identifiers include database names, table names, column names, and aliases.428. Avoid using reserved keywords as table or column names.529. A table’s degree is the number of columns.630. A table’s cardinality is the number of rows.7The booklet’s SQL worksheets specifically test NULL, table rows and columns, WHERE, GROUP BY, DISTINCT, UNION, transactions, and database structure.Complete-Placement-Preparation-Booklet-DSA-Core-Subjects-Interview-Guide.pdfSQL Command Categories
- DDL means Data Definition Language.
- DDL defines or changes database structure.
- Common DDL commands:
- CREATE.
- ALTER.
- DROP.
- TRUNCATE.
- CREATE DATABASE creates a database.
1CREATE DATABASE company;235. USE selects a database.1USE company;236. CREATE TABLE creates a table.1CREATE TABLE employees (2 employee_id INT PRIMARY KEY,3 employee_name VARCHAR(50),4 salary DECIMAL(10, 2),5 department_id INT6);737. ALTER TABLE modifies the structure of an existing table.838. Add a column:1ALTER TABLE employees2ADD email VARCHAR(100);339. Modify a column in MySQL:1ALTER TABLE employees2MODIFY employee_name VARCHAR(100);340. Rename a column in MySQL:1ALTER TABLE employees2RENAME COLUMN employee_name TO full_name;341. Drop a column:1ALTER TABLE employees2DROP COLUMN email;342. DROP TABLE removes both table structure and table data.1DROP TABLE employees;243. TRUNCATE TABLE removes all rows while retaining the table structure.1TRUNCATE TABLE employees;244. DML means Data Manipulation Language.345. Common DML commands:4 * INSERT.5 * UPDATE.6 * DELETE.746. INSERT adds rows.847. UPDATE modifies existing rows.948. DELETE removes rows.1049. DQL means Data Query Language.1150. SELECT is the primary DQL command.1251. DCL means Data Control Language.1352. GRANT gives privileges.1453. REVOKE removes privileges.1554. TCL means Transaction Control Language.1655. Common TCL commands:17 * COMMIT.18 * ROLLBACK.19 * SAVEPOINT.Table Creation and Constraints
- A constraint is a rule applied to table data.
- PRIMARY KEY uniquely identifies each row.
- A primary-key column cannot contain NULL.
- A table can have only one primary-key constraint.
- A primary key may contain multiple columns.
- A multi-column primary key is called a composite primary key.
- FOREIGN KEY creates a relationship between two tables.
- A foreign key references a primary key or candidate key in another table.
- A foreign key enforces referential integrity.
- UNIQUE prevents duplicate values.
- NOT NULL prevents missing values.
- DEFAULT provides a value when no value is supplied.
- CHECK restricts allowed values.
- Example:
1CREATE TABLE departments (2 department_id INT PRIMARY KEY,3 department_name VARCHAR(50) UNIQUE NOT NULL4);570. Example with a foreign key:1CREATE TABLE employees (2 employee_id INT PRIMARY KEY,3 employee_name VARCHAR(50) NOT NULL,4 salary DECIMAL(10, 2) CHECK (salary >= 0),5 department_id INT,6 FOREIGN KEY (department_id)7 REFERENCES departments(department_id)8);971. A foreign key may contain NULL if the relationship is optional.1072. A foreign key cannot contain a non-NULL value that does not exist in the referenced table.1173. ON DELETE CASCADE deletes dependent rows automatically.1274. ON UPDATE CASCADE updates dependent foreign-key values automatically.1375. ON DELETE SET NULL sets the foreign key to NULL, provided the column allows NULL.1476. ON DELETE RESTRICT prevents deletion of a referenced row if dependent rows exist.Data Types
- INT stores integer values.
- DECIMAL(p, s) stores exact fixed-point numbers.
- In DECIMAL(10, 2), 10 is the total number of digits and 2 is the number of digits after the decimal point.
- FLOAT and DOUBLE store approximate floating-point values.
- Use DECIMAL for money where exact precision is important.
- CHAR(n) stores fixed-length strings.
- VARCHAR(n) stores variable-length strings up to length n.
- CHAR may be useful when values have fixed length.
- VARCHAR is generally suitable for names, email addresses, and variable-length text.
- TEXT stores larger text values.
- DATE stores date values.
- TIME stores time values.
- DATETIME stores date and time.
- TIMESTAMP stores a timestamp and may have automatic update behavior depending on configuration.
- BOOLEAN in MySQL is commonly treated as a numeric type with values such as 0 and 1.
- Choose data types according to range, precision, storage, and application requirements.
INSERT, SELECT, UPDATE, and DELETE
- Insert one row:
1INSERT INTO departments (department_id, department_name)2VALUES (10, 'IT');394. Insert multiple rows:1INSERT INTO departments (department_id, department_name)2VALUES3 (20, 'HR'),4 (30, 'Sales'),5 (40, 'Finance');695. Select all columns:1SELECT *2FROM departments;396. Select specific columns:1SELECT department_id, department_name2FROM departments;397. Use an alias for a column:1SELECT department_name AS department2FROM departments;398. Filter rows with WHERE:1SELECT *2FROM employees3WHERE salary > 50000;499. Update rows:1UPDATE employees2SET salary = salary * 1.103WHERE department_id = 10;4100. Always use a proper WHERE condition in UPDATE unless every row should change.5101. Delete selected rows:1DELETE FROM employees2WHERE employee_id = 101;3102. Omitting WHERE from DELETE may remove every row.4103. SELECT does not permanently modify data.5104. INSERT, UPDATE, and DELETE modify table data.Operators and Filtering
- Comparison operators include:
- =.
- <> or !=.
-
.
- <.
-
=.
- <=.
- AND requires all conditions to be true.
1SELECT *2FROM employees3WHERE salary > 400004 AND department_id = 10;5107. OR requires at least one condition to be true.1SELECT *2FROM employees3WHERE department_id = 104 OR department_id = 20;5108. Use parentheses to control logical precedence.1SELECT *2FROM employees3WHERE department_id = 104 AND (salary > 40000 OR employee_name = 'Amit');5109. IN checks membership in a list.1SELECT *2FROM employees3WHERE department_id IN (10, 20, 30);4110. NOT IN excludes values from a list.5111. BETWEEN checks an inclusive range.1SELECT *2FROM employees3WHERE salary BETWEEN 30000 AND 60000;4112. BETWEEN includes both boundary values.5113. LIKE performs pattern matching.6114. % represents zero or more characters.7115. _ represents exactly one character.1SELECT *2FROM employees3WHERE employee_name LIKE 'A%';4This returns names beginning with A.1SELECT *2FROM employees3WHERE employee_name LIKE '_mit';4This may match Amit.5116. IS NULL checks for missing values.1SELECT *2FROM employees3WHERE department_id IS NULL;4117. IS NOT NULL checks for available values.5118. CASE performs conditional logic.1SELECT employee_name,2 CASE3 WHEN salary >= 80000 THEN 'High'4 WHEN salary >= 50000 THEN 'Medium'5 ELSE 'Low'6 END AS salary_level7FROM employees;SQL Execution Order
The logical processing order of a typical SQL query is:
- FROM.
- JOIN.
- WHERE.
- GROUP BY.
- HAVING.
- SELECT.
- DISTINCT.
- ORDER BY.
- LIMIT.
This explains why
- A SELECT alias may not be available in WHERE.
- Aggregate functions are generally filtered using HAVING.
- WHERE filters rows before grouping.
- HAVING filters groups after grouping.
Practice Drill
Module 1 Quiz
Practice Drill Bank
Every practice drill from the course, organised by module. Rehearse these until they feel automatic.
Final Revision Checklist
Tick items as you master them — progress saves automatically.
Module 1 – Module 1 – SQL Fundamentals · SQL Command Categories
Module 2 – Module 2 – Sorting, Grouping, and Aggregate Functions · Joins
Module 3 – Module 3 – Find total salary · Count employees
Module 4 – Module 4 – Duplicate salaries · Employees with duplicate names
Module 5 – Module 5 – Employees whose name starts with A · Employees hired in 2026
Module 6 – Module 6 – MySQL-Specific Concepts · ANSI SQL vs MySQL
Congratulations!
You've finished the CodeStudio SQL Essentials course. Revise, drill, and keep building.
Free SQL Notes & Query Practice for Placements
A free SQL revision course from SELECT filtering and grouping through joins, subqueries and CTEs to window functions, with the interview query shapes attached: second highest salary, top N per group, duplicate detection, running totals and date gaps.
It also covers NULL behaviour, HAVING versus WHERE, and the reasons a query is slow, so you can explain your answer rather than only produce it.
What you'll learn in SQL Essentials
- Module 1 – SQL Fundamentals · SQL Command Categories
- Module 2 – Sorting, Grouping, and Aggregate Functions · Joins
- Module 3 – Find total salary · Count employees
- Module 4 – Duplicate salaries · Employees with duplicate names
- Module 5 – Employees whose name starts with A · Employees hired in 2026
- Module 6 – MySQL-Specific Concepts · ANSI SQL vs MySQL
Why SQL Essentials matters for placements
SQL is the fastest core skill to convert into interview marks because the question bank is small and repeats. It also appears in analyst, backend and service-company rounds alike.
Free vs Premium — what's included
Free
- Every module on this page — open, no sign-up needed
- Key points, comparison tables and quick-revision notes
- MCQs and practice drills after each module
- Progress tracking saved in your browser
Premium
- Module-wise deep-dive course with worked examples
- Quizzes and interview question sets per module
- All 14 premium placement courses, lifetime access
- Company-specific preparation tracks
Frequently asked questions
Which SQL questions repeat in placement tests?
Ranking and top-N-per-group, second highest value, duplicates, joins with NULL handling and aggregate filtering with HAVING.
Do I need window functions?
Yes for product and analyst roles, and they simplify many classic answers, so learn ROW_NUMBER, RANK and DENSE_RANK with PARTITION BY.
Which SQL dialect is used here?
Standard SQL, with notes where MySQL and PostgreSQL syntax differ.