SQL Tutorial
Learn SQL to create, query and manage relational databases in MySQL, PostgreSQL, Oracle and SQL Server.
SQL (Structured Query Language) is the standard language for working with relational databases. It was developed at IBM in the 1970s (originally called SEQUEL) and standardised by ANSI in 1986 and ISO in 1987.
SQL Command Categories
| Category | Commands | Purpose |
|---|---|---|
| DDL | CREATE, ALTER, DROP, TRUNCATE, RENAME | Define structure |
| DML | INSERT, UPDATE, DELETE | Change data |
| DQL | SELECT | Query data |
| DCL | GRANT, REVOKE | Permissions |
| TCL | COMMIT, ROLLBACK, SAVEPOINT | Transactions |
Your First Query
Most examples use this employees table:
| id | name | dept | salary | city |
|---|---|---|---|---|
| 1 | Asha | IT | 65000 | Pune |
| 2 | Ravi | HR | 42000 | Mumbai |
| 3 | Meera | IT | 78000 | Pune |
| 4 | Karan | Sales | 51000 | Delhi |
| 5 | Neha | HR | 47000 | Pune |
SELECT name, salary FROM employees WHERE dept = 'IT';
+-------+--------+
| name | salary |
+-------+--------+
| Asha | 65000 |
| Meera | 78000 |
+-------+--------+
StyleSQL keywords aren't case-sensitive, but writing them in UPPERCASE makes queries easier to read. End each statement with a semicolon.
Track your progress through the SQL course