What is SQL?

SQL (Structured Query Language) is a standardized programming language used for managing and manipulating relational databases. It provides a set of commands that enable users to interact with databases to create, retrieve, update, and delete data. SQL is widely used in various applications and industries, ranging from simple web applications to complex enterprise systems.

At its core, SQL operates on tables, which are structured collections of data organized into rows and columns. Each column represents a specific attribute or field, while each row represents an individual record or entry. The table structure defines the schema, which specifies the column names and their data types.

Here is an example of a table schema for a hypothetical Employees table:

## Table: Employees

## | ID | Name | Age | Department |

| 1 | John | 30 | Sales |
| 2 | Lisa | 35 | Marketing |
| 3 | Mike | 28 | IT |
| 4 | Sarah | 32 | HR |

---

In the above example, the table Employees contains four columns: ID, Name, Age, and Department. Each row represents an employee with their respective attributes.

Now, let's explore ten concrete query examples that can be performed on the Employees table:

  1. Retrieve all employees:

SELECT * FROM Employees;

  1. Retrieve employees in the Sales department:

SELECT * FROM Employees WHERE Department = 'Sales';

  1. Retrieve employees younger than 30:

SELECT * FROM Employees WHERE Age < 30;

  1. Retrieve employees named John:

SELECT * FROM Employees WHERE Name = 'John';

  1. Retrieve employees with IDs 2 and 3:

SELECT * FROM Employees WHERE ID IN (2, 3);

  1. Retrieve employees sorted by age in descending order:

SELECT * FROM Employees ORDER BY Age DESC;

  1. Retrieve the number of employees in each department:

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

  1. Retrieve the average age of employees:

SELECT AVG(Age) FROM Employees;

  1. Update Lisa's department to Finance:

UPDATE Employees SET Department = 'Finance' WHERE Name = 'Lisa';

  1. Delete employees older than 35:

DELETE FROM Employees WHERE Age > 35;

These examples demonstrate how SQL can be used to retrieve specific data based on conditions, perform calculations, and modify existing data in a table. With SQL, users can effectively manage and query large volumes of data in a relational database system.

Was this page helpful?