0% found this document useful (0 votes)
3 views3 pages

Quick Reference - SQL Commands

This guide provides a quick reference to essential SQL commands for managing relational databases, including data retrieval, insertion, updating, and deletion. It also covers join operations and grouping with aggregates. Mastery of these commands is crucial for database professionals.

Uploaded by

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

Quick Reference - SQL Commands

This guide provides a quick reference to essential SQL commands for managing relational databases, including data retrieval, insertion, updating, and deletion. It also covers join operations and grouping with aggregates. Mastery of these commands is crucial for database professionals.

Uploaded by

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

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 E.name, D.dept_name


FROM Employees E
INNER JOIN Departments D ON E.dept_id = D.dept_id;

 Left Join:

SELECT E.name, 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.

You might also like