🧾 SQL Introduction

Last Updated: 7th January 2026


SQL (Structured Query Language) is a standard language used to communicate with relational databases.Using SQL, we can store, retrieve, update, and delete data from a database.


🤔 Why SQL Is Important?

  • Almost every application uses a database
  • SQL works with most relational databases
  • Easy to learn and very powerful
  • Required for backend, data analysis, and data engineering

Used in:

  • Web applications
  • Banking systems
  • Data analysis (with Python, Excel, BI tools)
  • Enterprise software

SQL Working Principle?

SQL is used with Relational Database Management Systems (RDBMS) such as:

  • MySQL
  • PostgreSQL
  • Oracle
  • SQL Server
  • SQLite

It execute in following steps:

  • SQL Query → Query Language Processor → DBMS Engine → Database

SQL Query?

An SQL Query is a command written in SQL to perform an operation on the database.

  • SQL queries are case-insensitive.
  • We Can terminate multiple commands with a semicolon (;).

Examples of operations:

  • Fetch data
  • Insert new data
  • Update existing data
  • Delete data

Example of a Simple SQL Query

SELECT * FROM students;

This query means:

  • SELECT → choose data
  • * → all columns
  • FROM students → from the students table

SQL Subquery?

A SQL Subquery is a query inside another query.

Example

SELECT *
FROM students
WHERE marks > (
  SELECT AVG(marks)
  FROM students
);

This query means:

  • SELECT → choose data
  • * → all columns
  • FROM students → from the students table
  • WHERE marks > → where marks are greater than
  • SELECT AVG(marks) → average marks from the students table

SQL Clause?

An SQL Clause is a part of an SQL query that defines how data should be selected or filtered.

A query is usually made of multiple clauses combined together.

Commonly Used SQL Clauses

  • SELECT → specifies columns
  • FROM → specifies table
  • WHERE → filters rows
  • ORDER BY → sorts result
  • GROUP BY → groups rows
  • HAVING → filters grouped data
  • LIMIT → restricts number of rows

Example Using Multiple Clauses

SELECT name, marks
FROM students
WHERE marks > 60
ORDER BY marks DESC;

Explanation:

  • Select name and marks
  • From students table
  • Only rows where marks are greater than 60
  • Sort results in descending order

SQL Operators And Functions?

An SQL Operator is a symbol or keyword used to perform specific operations in an SQL query.

An SQL Function is a predefined operation that performs a specific task in an SQL query.

  • Arithmetic Operators (+, -, \*, /, %)
  • Comparison Operators (>, <, >=, <=, =, !=, <>)
  • Logical Operators (AND, OR, NOT)
  • String Operators (LIKE, NOT LIKE, IN, NOT IN)
  • Date and Time Operators (DATE, TIME, TIMESTAMP)
  • NULL Handling Operators (IS NULL, IS NOT NULL)
  • Union and Intersect Operators (UNION, INTERSECT)
  • Aggregate Functions (COUNT, SUM, AVG, MAX, MIN)
  • Window Functions (RANK, ROW_NUMBER, DENSE_RANK)

SQL Comments?

SQL Comments are used to explain queries or disable code execution.They are ignored by the database engine. They are two Types.

Single-Line Comment (--)

-- This is a single-line comment
SELECT * FROM students;

Multi-Line Comment(/* */)

  • Improve code readability
  • Helpful for teams
  • Useful for debugging
/*
  This is a
  multi-line comment
*/
SELECT name FROM students;

⚠️ Important SQL Rules

  • SQL keywords are not case-sensitive (SELECT = select)
  • Table and column names depend on database settings
  • SQL statements usually end with a semicolon ;