SQL Clauses Operators Functions Reference
Posted on Apr 21, 2025 in Information and Documentation
SQL Clauses
| Clauses | How to Use It | Functionality |
|---|
| CREATE TABLE | CREATE TABLE table_name ... | Creates a new table |
| INSERT | INSERT INTO table_name ... | Inserts new data into the table |
| SELECT | SELECT col1, col2 ... | Retrieves specified columns |
| SELECT | SELECT * FROM ... | Retrieves all columns from a table |
| FROM | FROM table_name | Specifies the table(s) from which to retrieve data |
| WHERE | WHERE col > 5 | Filters rows based on specified conditions |
| UPDATE, SET | UPDATE table_name SET column1 = value1; | Updates column values for all rows (or specific rows with WHERE) |
| DELETE | DELETE FROM table_name | Deletes all rows from the table |
| DROP | DROP TABLE table_name | Deletes the table from the database |
| ALTER | ALTER TABLE table_name ... | Adds, deletes, or modifies columns in a table |
| ORDER BY | ORDER BY col1 ASC/DESC.. | Sorts rows based on column(s) in ascending or descending order |
| DISTINCT | SELECT DISTINCT col, ... | Retrieves unique values from specified column(s) |
| LIMIT | LIMIT 10 | Limits the number of rows returned |
| OFFSET | OFFSET 5 | Specifies the starting row for results (used with LIMIT) |
| GROUP BY | GROUP BY col ... | Groups rows with the same values in specified columns |
| HAVING | HAVING col > 20 | Filters grouped rows based on conditions |
| CASE | CASE WHEN condition1 THEN value1 WHEN .. ELSE .. END | Returns a value based on the first matching condition |
SQL Operators
| Operators | How to Use It | Functionality |
|---|
<> | WHERE col <> 5 | Filters rows where the column is not equal to a value. Includes comparison operators (=, >, <, >=, <=). |
| LIKE | WHERE col LIKE '%Apple%' | Retrieves rows where a column value matches a pattern |
| AND | WHERE col1 > 5 AND col2 < 3 | Retrieves rows satisfying all specified conditions |
| OR | WHERE col1 > 5 OR col2 < 3 | Retrieves rows satisfying at least one specified condition |
| NOT | WHERE NOT col = 'apple' | Retrieves rows where the condition(s) is NOT true |
| IN | WHERE col IN ('Apple', 'Microsoft') | Retrieves rows where a column value is in a list of values |
| BETWEEN | WHERE col BETWEEN 3 AND 5 | Retrieves rows where a column value is within a range (inclusive) |
SQL Functions
| Functions | How to Use It | Functionality |
|---|
| COUNT | SELECT COUNT(col) ... | Counts the number of values in a column |
| SUM | SELECT SUM(col) ... | Calculates the sum of values in a column |
| MIN | SELECT MIN(col) ... | Finds the minimum value in a column |
| MAX | SELECT MAX(col) ... | Finds the maximum value in a column |
| AVG | SELECT AVG(col) ... | Calculates the average of values in a column |
| strftime() | strftime("%Y", col) ... | Extracts date/time parts (like year) from a value. |
| CAST() | CAST(col AS datatype) ... | Converts a value to a specified datatype |
| FLOOR() | FLOOR(col) | Rounds a number down to the nearest integer |
| CEIL() | CEIL (col) | Rounds a number up to the nearest integer |
| ROUND() | ROUND(col) | Rounds a number to a specified decimal places |
| UPPER() | UPPER(col) | Converts a string to uppercase |
| LOWER() | Lower(col) | Converts a string to lowercase |