SQL Reference Guide

Comprehensive documentation for SQL commands and functions

Data Definition Language (DDL)

CREATE TABLE

Defines a new table in the database.

ALTER TABLE

Modifies an existing table's structure.

DROP TABLE

Deletes a table and all its data.

CREATE INDEX

Creates an index on a table's column(s).

DROP INDEX

Deletes an index.

Data Manipulation Language (DML)

SELECT

Retrieves data from one or more tables.

INSERT

Adds new rows of data to a table.

UPDATE

Modifies existing data in a table.

DELETE

Removes rows of data from a table.

Data Control Language (DCL)

GRANT

Gives user access privileges to the database.

REVOKE

Removes user access privileges.

Built-in Functions

COUNT()

Counts the number of rows.

SUM()

Calculates the sum of values in a column.

AVG()

Calculates the average of values.

MAX()

Finds the maximum value.

MIN()

Finds the minimum value.

CONCAT()

Concatenates strings.

UPPER()

Converts string to uppercase.

LOWER()

Converts string to lowercase.

SUBSTRING()

Extracts a part of a string.

CASE

Performs IF-THEN-ELSE logic.

Common Clauses

WHERE

Filters records based on a condition.

GROUP BY

Groups rows that have the same values.

HAVING

Filters groups based on a condition.

ORDER BY

Sorts the result set.

LIMIT

Restricts the number of rows returned.

JOIN Types

INNER JOIN

Returns rows when there is a match in both tables.

LEFT JOIN

Returns all rows from the left table, and the matched rows from the right table.

RIGHT JOIN

Returns all rows from the right table, and the matched rows from the left table.

FULL OUTER JOIN

Returns all rows from both tables, with NULLs where no match exists.

CROSS JOIN

Returns the Cartesian product of rows from both tables.