SQL Clauses Operators Functions Reference

SQL Clauses

ClausesHow to Use ItFunctionality
CREATE TABLECREATE TABLE table_name ...Creates a new table
INSERTINSERT INTO table_name ...Inserts new data into the table
SELECTSELECT col1, col2 ...Retrieves specified columns
SELECTSELECT * FROM ...Retrieves all columns from a table
FROMFROM table_nameSpecifies the table(s) from which to retrieve data
WHEREWHERE col > 5Filters rows based on specified conditions
UPDATE, SETUPDATE table_name SET column1 = value1;Updates column values for all rows (or specific rows with WHERE)
DELETEDELETE FROM table_nameDeletes all rows from the table
DROPDROP TABLE table_nameDeletes the table from the database
ALTERALTER TABLE table_name ...Adds, deletes, or modifies columns in a table
ORDER BYORDER BY col1 ASC/DESC..Sorts rows based on column(s) in ascending or descending order
DISTINCTSELECT DISTINCT col, ...Retrieves unique values from specified column(s)
LIMITLIMIT 10Limits the number of rows returned
OFFSETOFFSET 5Specifies the starting row for results (used with LIMIT)
GROUP BYGROUP BY col ...Groups rows with the same values in specified columns
HAVINGHAVING col > 20Filters grouped rows based on conditions
CASECASE WHEN condition1 THEN value1 WHEN .. ELSE .. ENDReturns a value based on the first matching condition

SQL Operators

OperatorsHow to Use ItFunctionality
<>WHERE col <> 5Filters rows where the column is not equal to a value. Includes comparison operators (=, >, <, >=, <=).
LIKEWHERE col LIKE '%Apple%'Retrieves rows where a column value matches a pattern
ANDWHERE col1 > 5 AND col2 < 3Retrieves rows satisfying all specified conditions
ORWHERE col1 > 5 OR col2 < 3Retrieves rows satisfying at least one specified condition
NOTWHERE NOT col = 'apple'Retrieves rows where the condition(s) is NOT true
INWHERE col IN ('Apple', 'Microsoft')Retrieves rows where a column value is in a list of values
BETWEENWHERE col BETWEEN 3 AND 5Retrieves rows where a column value is within a range (inclusive)

SQL Functions

FunctionsHow to Use ItFunctionality
COUNTSELECT COUNT(col) ...Counts the number of values in a column
SUMSELECT SUM(col) ...Calculates the sum of values in a column
MINSELECT MIN(col) ...Finds the minimum value in a column
MAXSELECT MAX(col) ...Finds the maximum value in a column
AVGSELECT 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