Docsity

SQL for Beginners – Complete Database & Interview Guide 2026, Summaries of Computer science

Partial preview of the text

Download SQL for Beginners – Complete Database & Interview Guide 2026 and more Summaries Computer science in PDF only on Docsity!

SQL for Beginners – 2026

Complete Database & Interview Guide

For BCA, BSc CS, BTech, IT, Engineering & College Students

A practical beginner-friendly guide covering SQL fundamentals, databases, queries, joins, subqueries,

database design, interview preparation and hands-on practice.

Table of Contents

    1. Introduction to SQL
    1. Databases & Tables
    1. Data Types
    1. SELECT & DISTINCT
    1. WHERE & Filtering
    1. ORDER BY & LIMIT
    1. Aggregate Functions
    1. GROUP BY & HAVING
    1. INSERT, UPDATE & DELETE
    1. NULL Values
    1. LIKE, IN & BETWEEN
    1. JOINs
    1. Subqueries
    1. CASE Expressions
    1. String Functions
    1. Date & Numeric Functions
    1. Keys & Constraints
    1. Normalization
    1. Views & Indexes
    1. Transactions
    1. Interview Questions
    1. Practical Queries
    1. Mini Project
    1. Common Mistakes
    1. 30-Day Roadmap
  • Quick Revision
  • Practice Questions 1. Introduction to SQL

SQL stands for Structured Query Language. It is used to retrieve and manage data in relational database

systems. SQL is a core skill for software development, data analytics, reporting and database-related

roles.

2. Databases & Tables

A relational database stores information in tables. Tables contain rows (records) and columns (attributes).

  • MAX() – maximum.

SELECT COUNT(*) AS total, AVG(marks) AS average, MAX(marks) AS highest FROM students;

8. GROUP BY & HAVING

SELECT city, COUNT(*) AS total_students FROM students GROUP BY city;

SELECT department_id, AVG(marks) AS avg_marks FROM students GROUP BY department_id HAVING AVG(marks) >= 70;

WHERE filters individual rows; HAVING filters grouped results after aggregation.

9. INSERT, UPDATE & DELETE

INSERT INTO students (student_id,name,marks,city) VALUES (101,'Asha',82,'Nagpur');

UPDATE students SET marks= WHERE student_id=101;

DELETE FROM students WHERE student_id=101;

Always check the WHERE condition before UPDATE or DELETE.

10. NULL Values

NULL means missing or unknown information. It is not the same as zero.

SELECT * FROM students WHERE city IS NULL; SELECT * FROM students WHERE city IS NOT NULL;

11. LIKE, IN & BETWEEN

SELECT name FROM students WHERE name LIKE 'A%'; SELECT * FROM students WHERE city IN ('Pune','Nagpur'); SELECT * FROM students WHERE marks BETWEEN 60 AND 80;

In LIKE, % commonly represents zero or more characters and _ represents one character.

12. JOINs

JOINs combine related data from multiple tables.

SELECT s.name, d.department_name FROM students s INNER JOIN departments d ON s.department_id = d.department_id;

  • INNER JOIN – matching rows.
  • LEFT JOIN – all left rows plus matches.
  • RIGHT JOIN – all right rows plus matches.
  • FULL OUTER JOIN – all rows where supported.
  • CROSS JOIN – combinations of rows. 13. Subqueries

SELECT name, marks FROM students WHERE marks > (SELECT AVG(marks) FROM students);

A subquery is a query nested inside another query.

14. CASE Expressions

SELECT name, marks, CASE WHEN marks >= 75 THEN 'Distinction' WHEN marks >= 60 THEN 'First Class' WHEN marks >= 40 THEN 'Pass' ELSE 'Fail' END AS result FROM students;

15. String Functions - UPPER() – uppercase. - LOWER() – lowercase. - TRIM() – remove surrounding spaces. - CONCAT() – combine text. - LENGTH()/LEN() – length depending on database.

SELECT UPPER(name) AS student_name FROM students;

16. Date & Numeric Functions

SELECT ROUND(price,2) FROM products; SELECT EXTRACT(YEAR FROM order_date) FROM orders;

Exact date syntax differs across SQL dialects, so learn the syntax used by your chosen database.

17. Keys & Constraints - PRIMARY KEY – uniquely identifies a row. - FOREIGN KEY – links related tables. - NOT NULL – requires a value. - UNIQUE – prevents duplicates. - CHECK – validates a condition where supported. - DEFAULT – supplies a default value.

What is a JOIN?

It combines related rows from tables.

What is normalization?

A design approach that reduces redundancy and improves integrity.

What is an index?

A structure that can speed up suitable queries.

What is a view?

A saved query represented like a virtual table.

What is NULL?

A marker for missing or unknown information.

Does correlation prove causation?

No; association alone does not establish cause.

22. Practical SQL Queries

Find students above 80 marks.

SELECT * FROM students WHERE marks > 80;

Find students from Pune.

SELECT name FROM students WHERE city='Pune';

Find the highest marks.

SELECT MAX(marks) FROM students;

Count students by city.

SELECT city, COUNT(*) FROM students GROUP BY city;

Find average marks by department.

SELECT department_id, AVG(marks) FROM students GROUP BY department_id;

Find students above average.

SELECT name, marks FROM students WHERE marks > (SELECT AVG(marks) FROM students);

Find names beginning with A.

SELECT name FROM students WHERE name LIKE 'A%';

Find missing city values.

SELECT name FROM students WHERE city IS NULL;

Find top 5 marks.

SELECT name, marks FROM students ORDER BY marks DESC LIMIT 5;

Join students and departments.

SELECT s.name,d.department_name FROM students s JOIN departments d ON s.department_id=d.department_id;

23. Mini Database Project

Build a Student Management Database using students, departments and courses tables.

  • Create the tables and relationships.
  • Insert sample records.
  • Write at least 20 SELECT queries.
  • Calculate averages and counts.
  • Use JOINs and a subquery.
  • Find top-performing students.
  • Document 5 useful insights. 24. Common Mistakes
  • Forgetting WHERE in UPDATE/DELETE.
  • Using the wrong JOIN condition.
  • Ignoring NULL values.
  • Not checking duplicates after JOINs.
  • Using SELECT * unnecessarily.
  • Assuming all SQL databases use identical syntax.
  • Not testing queries with sample data. 25. 30-Day SQL Roadmap
  • Days 1–4: SQL basics, databases, tables and data types.
  • Days 5–8: SELECT, WHERE, LIKE, IN, BETWEEN.
  • Days 9–12: ORDER BY, aggregates, GROUP BY, HAVING.
  • Days 13–16: INSERT, UPDATE, DELETE and NULL.
  • Days 17–21: JOINs and subqueries.
  • Days 22–24: CASE, strings, dates, keys and constraints.