0% found this document useful (0 votes)
18 views4 pages

My SQL Map

My Sql Map

Uploaded by

karthik3680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

My SQL Map

My Sql Map

Uploaded by

karthik3680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Comprehensive SQL Learning Roadmap

1. SQL Basics

- SQL Syntax: Basic SQL commands like SELECT, INSERT, UPDATE, DELETE.

Example:

SELECT * FROM Employees WHERE Department = 'Sales';

- Data Types: Common data types include INT, VARCHAR, DATE, etc.

Example:

CREATE TABLE Employees (EmployeeID INT, Name VARCHAR(100), HireDate DATE);

- Filtering Data: Use WHERE to filter rows.

Example:

SELECT Name FROM Employees WHERE Salary > 50000;

- Sorting Data: Use ORDER BY to sort the result.

Example:

SELECT Name, Salary FROM Employees ORDER BY Salary DESC;

- Basic Operators: SQL has comparison (e.g., =, <, >) and logical operators (e.g., AND, OR).

Example:

SELECT * FROM Employees WHERE Salary > 50000 AND Department = 'IT';

2. Joins and Relationships

- INNER JOIN: Combines rows from two or more tables based on a related column.

Example:

SELECT Employees.Name, Departments.DepartmentName


FROM Employees INNER JOIN Departments ON Employees.DepartmentID =

Departments.DepartmentID;

- LEFT JOIN: Retrieves all records from the left table, and matched records from the right table.

Example:

SELECT Employees.Name, Departments.DepartmentName

FROM Employees LEFT JOIN Departments ON Employees.DepartmentID =

Departments.DepartmentID;

- Primary and Foreign Keys: Used to uniquely identify rows and enforce relationships.

Example:

CREATE TABLE Departments (

DepartmentID INT PRIMARY KEY,

DepartmentName VARCHAR(100)

);

CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY,

Name VARCHAR(100),

DepartmentID INT,

FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)

);

3. Aggregate Functions

- COUNT: Returns the number of rows.

Example:

SELECT COUNT(*) FROM Employees;


- SUM: Adds up numeric values.

Example:

SELECT SUM(Salary) FROM Employees WHERE Department = 'Sales';

- GROUP BY: Groups rows that share a property, often used with aggregate functions.

Example:

SELECT Department, AVG(Salary) FROM Employees GROUP BY Department;

- HAVING: Filters groups after GROUP BY.

Example:

SELECT Department, COUNT(*) FROM Employees GROUP BY Department HAVING

COUNT(*) > 10;

4. Subqueries

- Simple Subquery: A query inside another query.

Example:

SELECT Name FROM Employees WHERE DepartmentID = (SELECT DepartmentID FROM

Departments WHERE DepartmentName = 'IT');

- Correlated Subquery: Refers to the outer query, executed row by row.

Example:

SELECT Name, Salary FROM Employees E WHERE Salary > (SELECT AVG(Salary) FROM

Employees WHERE DepartmentID = E.DepartmentID);

5. Set Operations

- UNION: Combines result sets of two queries, removing duplicates.


Example:

SELECT Name FROM Employees UNION SELECT Name FROM Contractors;

- UNION ALL: Similar to UNION, but allows duplicates.

Example:

SELECT Name FROM Employees UNION ALL SELECT Name FROM Contractors;

You might also like