1. Foundational Concepts
INT
, VARCHAR
, CHAR
, DATE
, DATETIME
, DECIMAL
, BOOLEAN
Example: CREATE TABLE Customers (CustomerID INT, CustomerName VARCHAR(255), City VARCHAR(255))
SELECT
: Retrieve data from one or more tables.SELECT * FROM Customers;
FROM
: Specifies the table to retrieve data from.SELECT CustomerName FROM Customers;
WHERE
: Filters data based on conditions.SELECT * FROM Customers WHERE City = 'New York';
ORDER BY
: Sorts the result set.SELECT * FROM Customers ORDER BY CustomerName ASC;
LIMIT
: Limits the number of rows returned.SELECT * FROM Customers LIMIT 10;
INSERT
: Adds new rows to a table.INSERT INTO Customers (CustomerID, CustomerName, City) VALUES (1, 'John Doe', 'New York');
UPDATE
: Modifies existing data in a table.UPDATE Customers SET City = 'Los Angeles' WHERE CustomerID = 1;
DELETE
: Removes rows from a table.DELETE FROM Customers WHERE City = 'New York';
CREATE TABLE
: Creates a new table with specified columns and data types.CREATE TABLE Orders (OrderID INT, CustomerID INT, OrderDate DATE);
DROP TABLE
: Deletes an entire table.DROP TABLE Orders;
ALTER TABLE
: Modifies the structure of a table (add, modify, or drop columns).ALTER TABLE Customers ADD Email VARCHAR(255);
2. Working with Multiple Tables
INNER JOIN
: Returns rows where there is a match in both tables.LEFT JOIN
: Returns all rows from the left table and matching rows from the right table.RIGHT JOIN
: Returns all rows from the right table and matching rows from the left table.FULL OUTER JOIN
: Returns all rows1 from both tables.3. Advanced SQL
SUM
, AVG
, COUNT
, MIN
, MAX
Example: SELECT AVG(Price) FROM Products;
SELECT Country, COUNT(*) FROM Customers GROUP BY Country;
SELECT Country, COUNT(*) FROM Customers GROUP BY Country HAVING COUNT(*) > 5;
RANK
, ROW_NUMBER
, LAG
, LEAD
).4. Database Administration
5. Practice and Projects
Important Notes:
This roadmap provides a structured approach to learning SQL. Remember to adapt it to your learning style and pace.