Quick Reference – SQL Commands
Structured Query Language (SQL) is used to manage and manipulate relational
databases. This guide covers the most commonly used SQL commands that are essential
for day-to-day database operations.
📄 1. Data Retrieval – SELECT Statement
Retrieve all records from a table:
SELECT * FROM Employees;
Retrieve specific columns:
SELECT name, salary FROM Employees;
With filtering conditions:
SELECT * FROM Employees WHERE salary > 50000;
Sorting results:
SELECT * FROM Employees ORDER BY name ASC;
➕ 2. Data Insertion – INSERT INTO
Insert a complete row:
INSERT INTO Employees VALUES (101, 'Alice', 'HR', 60000);
Insert specific columns only:
INSERT INTO Employees (id, name) VALUES (102, 'Bob');
🔄 3. Updating Records – UPDATE
Update a single field:
UPDATE Employees SET salary = 70000 WHERE id = 101;
Update multiple fields:
UPDATE Employees SET department = 'Finance', salary = 65000 WHERE id =
102;
❌ 4. Deleting Records – DELETE
Delete specific rows:
DELETE FROM Employees WHERE department = 'HR';
Delete all rows (use with caution):
DELETE FROM Employees;
🔗 5. Join Operations
Inner Join:
SELECT [Link], D.dept_name
FROM Employees E
INNER JOIN Departments D ON E.dept_id = D.dept_id;
Left Join:
SELECT [Link], D.dept_name
FROM Employees E
LEFT JOIN Departments D ON E.dept_id = D.dept_id;
📊 6. Grouping & Aggregates
Group records and apply aggregate functions:
SELECT department, COUNT(*) AS total_employees
FROM Employees
GROUP BY department;
Filter grouped data using HAVING:
SELECT department, AVG(salary)
FROM Employees
GROUP BY department
HAVING AVG(salary) > 50000;
✅ Conclusion
These SQL commands form the foundation for working with relational databases.
Mastery of these commands is essential for database developers, analysts, and backend
engineers.