MySQL Date, Time, and Functions Guide
MySQL Date, Time, and Functions Guide
MySQL Memento
Function Exit Function Exit
Command line help DATE YYYY-MM-DD ABS(n) absolute value
TIME HH:MM:SS SIGN(n) signe : 0, -1, 1
helporder; send back the help of order
DATETIME YYYY-MM-DD HH:MM:SS FLOOR, CEILING, ROUNDn) arrondi : inférieur, supérieur, plus proche
Creation/manipulation of databases and tables
YEAR(2|4) year in 2 or 4 digits ROUND, TRUNCATE (n, d) rounding or truncation to decimals
MONTH(date) month number EXP(x) POW(x,y) e x , xy
Order Significance HOUR(date) hour LOG (LN), LOG2, LOG10 (n) logarithme népérien, base 2, base 10
CREATE DATABASEname; create the database name MINUTE(date) minute COS, SIN, TAN, COT (n) trigonometric functions
DROP DATABASEname; delete the database
USE DATABASEname; select the database name
SECOND(date) second ACOS, ASIN, ATANn) inverse trigonometric functions
CURRENT_DATE()current date DEGREES, RADIANSn) conversion of angles in degrees, in radians
CREATE TABLEname; create the table name
DESCRIBETABLEname; show the format of the tablename CURRENT TIME()current time PI() the numberπ
ALTER TABLEname; modify the tablenom NOW() current date and time RAND() random decimal number between 0 and 1
DROPTABLEname; clear the table name
INSERT INTOtableVALUES (...); insert values
DELETE FROMtableWHEREcondition; delete records Aggregation functions (GROUP BY) Various functions
SHOW TABLES; display the tables of the chosen database
Order Exit Function Exit
Numeric data AVG(expr) average value CONCAT(ch1, ch2, ...) concatenate the strings
Type Signification COUNT(expr) count the lines LENGTH(ch) return the length of the string
MIN(expr) minimum REVERSE(ch) reverse the string
TINYINT integer coded on 1 byte MAX(expr) maximum STRCMP(ch1, ch2) string comparison
SMALLINT integer coded on 2 bytes STD(expr) standard deviation UCASE(ch) put the chain in uppercase
MEDIUMINT integer coded on 3 bytes SUM(expr) sum LCASE(ch) make the string lowercase
INT, INTEGER integer coded on 4 bytes VARIANCE(expr) variance ORD(ch) ASCII code of the first element of the string
BIGINT integer coded on 8 bytes
FLOAT[(m,d)] single precision floating point number
SQL Queries (Generic Syntax followed by examples)
DOUBLE(m,d)] double precision floating point number
DECIMAL[(m,d)] floating point number absolute precision Order Significance
SELECTcol1 [, col2, ... or *] column selection
Character type data
FROMtable1 [, table2, ...] one or more tables
Type Significance WHEREcondition condition
GROUP BYcriterion gather the tables into groups
CHAR(n) string (0É nÉ 255)
HAVINGcondition condition on a group
VARCHAR(n) string (0É nÉ 255)
{UNION | INTERCEPT | EXCEPT} combine several requests
TINYTEXT(n) stringÉ n É 255)
ORDER BYexpression sort the results
TEXT(n) string (0É nÉ 65535)
LIMIT[offset,] n limit to records (after the offset)
MEDIUMTEXT(n) string (0É nÉ 16777215)
LONGTEXT(n) string (0É nÉ 4294967295) SELECT * FROMtable; return all columns
ENUM('a','b', ...) 1 value in the list SELECTcolumnFROMtable; return the entire column
SET('a', 'b', ...) 1 or several values in the list SELECT COUNT(*) FROMtable; return the number of lines
SELECT MAX(column) ASname; return the maximum of the column accessible by the name
Common operators SELECT DISTINCTcolumnFROMtable; return the distinct values of the column
SELECT * FROMtableWHEREcondition; return the data that meets the condition
Type Significance
SELECT * FROMtable1
*, /, +, - arithmetic operations INNER [Link] = [Link]; joins table1 and table2 on the ID criterion
DIV, % (or MOD) integer division, remainder SELECT * FROMtableORDER BYcolumn; return all the lines sorted according to the data from
AND (&&), OR (||) , NOT (!) logical operations column
<, =, >, <=, >=, != or <> comparisons SELECT * FROMtableLIMIT 3,10; return 10 lines after the 3rd (so from 4 to 13)
IS boolean test INSERT INTOtableVALUES ('value1', 'value2', ...); insert data into the table
LIKE search for patterns DELETE FROMtableWHEREcondition; delete the records that meet the condition