Structured Query Language (SQL) is the standard language for managing and manipulating relational databases. Whether you’re a data analyst, software developer, or aspiring data engineer, understanding SQL is crucial for interacting with data efficiently. This article will serve as a comprehensive set of SQL notes that you can refer to for learning or revision.
Pdf Notes :- https://drive.google.com/file/d/1UV6_BEKLAiWXxRhDnjpggaqbhdmoWESX/view?usp=sharing
📌 What is SQL?
SQL stands for Structured Query Language. It is used to communicate with relational databases. SQL lets you create, read, update, and delete data — commonly known as CRUD operations.
Some of the most popular database systems that use SQL are:
-
MySQL
-
PostgreSQL
-
SQLite
-
Oracle
-
Microsoft SQL Server
🔹 Basic SQL Syntax
Here’s an example SQL query to fetch data from a table:
This statement reads:
-
SELECT
the columnsfirst_name
andlast_name
-
FROM
the table calledemployees
-
WHERE
thedepartment
is ‘Sales’
🏗️ SQL Data Types
When creating tables, it’s important to define the correct data types for each column:
-
INT
: Integer values -
VARCHAR(n)
: Variable-length string up to n characters -
DATE
: Date values (YYYY-MM-DD) -
FLOAT
orDECIMAL
: Decimal numbers -
BOOLEAN
: True/False values
🛠️ Creating Tables
To store data in a database, you first need to create tables.
✏️ Inserting Data
Once a table is created, you can insert records using INSERT INTO
:
📤 Retrieving Data
Use the SELECT
statement to query data:
This selects all columns for all rows in the students
table. You can filter results using the WHERE
clause:
🔄 Updating and Deleting Data
You can modify data using UPDATE
:
To remove data, use DELETE
:
🔍 SQL Clauses and Keywords
Some commonly used SQL clauses include:
-
ORDER BY
: Sorts results (ascending by default) -
GROUP BY
: Groups rows that have the same values -
HAVING
: Filters groups (used withGROUP BY
) -
JOIN
: Combines rows from two or more tables -
LIMIT
: Restricts number of rows returned
Example of ORDER BY
:
🔗 SQL Joins
Joins are used to fetch data from multiple related tables.
-
INNER JOIN
: Returns records with matching values in both tables -
LEFT JOIN
: Returns all records from the left table and matched records from the right -
RIGHT JOIN
: Opposite of LEFT JOIN -
FULL OUTER JOIN
: Returns all records when there is a match in either table
Example:
📊 Aggregate Functions
SQL supports built-in functions for calculations:
-
COUNT()
: Number of rows -
SUM()
: Total value -
AVG()
: Average -
MIN()
/MAX()
: Smallest/largest value
Example:
🧩 Subqueries and Aliases
A subquery is a query nested inside another:
Aliases make column/table names more readable:
🧼 Best Practices
-
Always back up data before performing
DELETE
orUPDATE
-
Use
WHERE
to limit scope of changes -
Name tables and columns clearly
-
Indent and format your queries for readability
🚀 Conclusion
SQL is a powerful and essential tool for anyone working with data. Whether you’re writing simple queries or complex joins, understanding SQL helps you unlock the full potential of relational databases. Practice is key, so try out queries on sample datasets or use online platforms like or Mode SQL Tutorial to improve your skills.
Keep this SQL notes guide handy as your quick reference, and happy querying!