- SELECT Statement:
- Definition: Retrieves data from one or more tables.
- Example:
SELECT column1, column2 FROM table WHERE condition;
- INSERT INTO Statement:
- Definition: Adds new records to a table.
- Example:
INSERT INTO table (column1, column2) VALUES (value1, value2);
- UPDATE Statement:
- Definition: Modifies existing records in a table.
- Example:
UPDATE table SET column1 = value1 WHERE condition;
- DELETE Statement:
- Definition: Removes records from a table.
- Example:
DELETE FROM table WHERE condition;
- CREATE TABLE Statement:
- Definition: Creates a new table.
- Example:
CREATE TABLE table (column1 datatype, column2 datatype);
- ALTER TABLE Statement:
- Definition: Modifies an existing table structure.
- Example:
ALTER TABLE table ADD column3 datatype;
- DROP TABLE Statement:
- Definition: Deletes an existing table.
- Example:
DROP TABLE table;
- SELECT DISTINCT Statement:
- Definition: Retrieves unique values from a column.
- Example:
SELECT DISTINCT column1 FROM table;
- COUNT() Function:
- Definition: Counts the number of rows in a result set.
- Example:
SELECT COUNT(column1) FROM table WHERE condition;
- GROUP BY Clause:
- Definition: Groups rows based on the values in specified columns.
- Example:
SELECT column1, COUNT(column2) FROM table GROUP BY column1;
- SELECT Statement:
- Retrieves data from one or more tables.
- WHERE Clause:
- Filters records based on a specified condition.
- ORDER BY Clause:
- Sorts the result set in ascending or descending order.
- GROUP BY Clause:
- Groups rows based on the values in specified columns.
- COUNT() Function:
- Counts the number of rows in a result set.
- SUM() Function:
- Calculates the sum of values in a numeric column.
- AVG() Function:
- Calculates the average value of a numeric column.
- MIN() Function:
- Retrieves the smallest value in a column.
- MAX() Function:
- Retrieves the largest value in a column.
- INNER JOIN:
- Combines rows from two or more tables based on a related column.
- LEFT JOIN:
- Retrieves all rows from the left table and the matched rows from the right table.
- RIGHT JOIN:
- Retrieves all rows from the right table and the matched rows from the left table.
- FULL OUTER JOIN:
- Retrieves all rows when there is a match in either the left or right table.
- HAVING Clause:
- Filters the result set based on aggregate values.
- DISTINCT Keyword:
- Retrieves unique values from a column.
- LIKE Operator:
- Searches for a specified pattern in a column.
- IN Operator:
- Specifies multiple values for a WHERE clause.
- BETWEEN Operator:
- Retrieves values within a specified range.
- CASE Statement:
- Performs conditional logic within a query.
- UNION Operator:
- Combines the result sets of two or more SELECT statements.
- DISTINCT Keyword:
- Retrieves unique values from a column.
- LIKE Operator:
- Searches for a specified pattern in a column.
- IN Operator:
- Specifies multiple values for a WHERE clause.
- BETWEEN Operator:
- Retrieves values within a specified range.
- CASE Statement:
- Performs conditional logic within a query.
- UNION Operator:
- Combines the result sets of two or more SELECT statements.
- INTERSECT Operator:
- Retrieves common rows between two SELECT statements.
- EXCEPT Operator:
- Retrieves rows from the first SELECT statement that are not present in the second.
- AS Keyword:
- Renames a column or table in the result set.
- IS NULL Operator:
- Checks for NULL values in a column.
- IS NOT NULL Operator:
- Checks for non-NULL values in a column.
- INNER JOIN with USING:
- Joins tables based on a common column using the USING keyword.
- LEFT JOIN with USING:
- Retrieves all rows from the left table and matched rows from the right using the USING keyword.
- RIGHT JOIN with USING:
- Retrieves all rows from the right table and matched rows from the left using the USING keyword.
- FULL OUTER JOIN with USING:
- Retrieves all rows when there is a match in either the left or right table using the USING keyword.
- COUNT(DISTINCT Column):
- Counts the number of unique values in a column.
- CONCAT() Function:
- Concatenates two or more strings.
- UPPER() Function:
- Converts a string to uppercase.
- LOWER() Function:
- Converts a string to lowercase.
- LENGTH() Function:
- Returns the length of a string.
- TRIM() Function:
- Removes leading and trailing spaces from a string.
- ROUND() Function:
- Rounds a numeric value to the nearest integer.
- RAND() Function:
- Generates a random decimal value between 0 and 1.
- CURRENT_DATE Function:
- Retrieves the current date.
- CURRENT_TIME Function:
- Retrieves the current time.
- CURRENT_TIMESTAMP Function:
- Retrieves the current timestamp.
- DATEDIFF() Function:
- Calculates the difference between two dates.
- COALESCE() Function:
- Returns the first non-NULL value in a list.
- NULLIF() Function:
- Returns NULL if two expressions are equal; otherwise, returns the first expression.
- ROW_NUMBER() Function:
- Assigns a unique number to each row within a partition of a result set.
- RANK() Function:
- Assigns a rank to each row within a result set.
- DENSE_RANK() Function:
- Assigns a dense rank to each row within a result set.
- LEAD() Function:
- Accesses data from a subsequent row within the same result set.
- LAG() Function:
- Accesses data from a preceding row within the same result set.
- PARTITION BY Clause:
- Divides the result set into partitions to which the window function is applied.
- FIRST_VALUE() Function:
- Returns the first value in an ordered set of values.
- LAST_VALUE() Function:
- Returns the last value in an ordered set of values.
- NTH_VALUE() Function:
- Returns the nth value in an ordered set of values.
- HAVING COUNT() > 1:
- Filters groups based on having more than one occurrence.
- CASCADE Option in DELETE:
- Deletes all rows in child tables when a record in the parent table is deleted.
- SET NULL Option in DELETE:
- Sets foreign key columns to NULL in child tables when a record in the parent table is deleted.
- SET DEFAULT Option in DELETE:
- Sets foreign key columns to their default values in child tables when a record in the parent table is deleted.
- CASCADE Option in UPDATE:
- Updates foreign key values in child tables when a record in the parent table is updated.
- SET NULL Option in UPDATE:
- Sets foreign key columns to NULL in child tables when a record in the parent table is updated.
- SET DEFAULT Option in UPDATE:
- Sets foreign key columns to their default values in child tables when a record in the parent table is updated.
- FOR UPDATE Clause:
- Locks rows selected for update, preventing other users from modifying them.
- FOR SHARE Clause:
- Locks rows selected for read, preventing other users from updating or deleting them.
- UNION ALL Operator:
- Combines the result sets of two or more SELECT statements, including duplicates.
- CHECK Constraint:
- Ensures that values in a column meet specific conditions.
- PRIMARY KEY Constraint:
- Enforces the uniqueness of values in a column or a set of columns.
- FOREIGN KEY Constraint:
- Establishes a link between data in two tables, preventing actions that would destroy the link.
- DEFAULT Constraint:
- Provides a default value for a column when no value is specified.
- INDEX:
- Improves the speed of data retrieval operations on a database table.
- CREATE VIEW Statement:
- Creates a virtual table based on the result set of a SELECT statement.
- CREATE INDEX Statement:
- Creates an index on a table.
- ALTER INDEX Statement:
- Modifies an existing index.
- DROP INDEX Statement:
- Removes an index from a table.
- TRANSACTION:
- A sequence of one or more SQL statements treated as a single unit of work.
- COMMIT Statement:
- Saves changes made during the current transaction.
- ROLLBACK Statement:
- Undoes changes made during the current transaction.
- SAVEPOINT Statement:
- Sets a point within a transaction to which you can later roll back.
- ROLLBACK TO SAVEPOINT Statement:
- Undoes all changes made since a specified savepoint was established.
- SET TRANSACTION ISOLATION LEVEL:
- Sets the isolation level for the current transaction.
- UNIQUE Constraint:
- Ensures that all values in a column or a set of columns are unique.
- JOIN Clause:
- Combines rows from two or more tables based on a related column.
- EXISTS Operator:
- Tests for the existence of any records in a subquery.
- NOT EXISTS Operator:
- Tests for the non-existence of any records in a subquery.
- ANY Operator:
- Compares a value to any value in a list or a subquery.
- ALL Operator:
- Compares a value to all values in a list or a subquery.
- CASE Expression:
- Performs conditional logic within a SELECT statement.
- COALESCE() Function:
- Returns the first non-NULL value in a list.
- NULLIF() Function:
- Returns NULL if two expressions are equal; otherwise, returns the first expression.
- CURRENT_USER Function:
- Retrieves the current user.
- SESSION_USER Function:
- Retrieves the session user.
- DATABASE() Function:
- Retrieves the current database name.
- LIMIT Clause:
- Specifies the number of rows to return in a result set.
- OFFSET Clause:
- Specifies the number of rows to skip before starting to return rows.
- FETCH FIRST n ROWS ONLY Clause:
- Limits the number of rows returned in a result set.
- FETCH NEXT n ROWS ONLY Clause:
- Retrieves the next n rows from a result set.
- FETCH LAST n ROWS ONLY Clause: - Retrieves the last n rows from a result set.
- These SQL formulas cover a wide range of functionalities within SQL. If you have specific areas of interest or if you need more examples in a particular category, feel free to let me know!