MySQL Tips and Functions
• Comparison operators | |
= | Equals |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
<> | Not equal to |
!= | Not equal to |
LIKE | Compare strings |
• Mathematical operators | |
( ) | Use parentheses to force precedence |
+ | add |
– | subtract |
* | multiply |
/ | divide |
% | modulo |
• Conditional operators | |
|| | Logical “or” |
| | Bitwise “or” |
OR | Same as Logical “or” |
&& | Logical “and” |
& | Bitwise “and” |
AND | Same as Logical “and” |
• Some Common Functions | |
CONCAT(str1,str2) | Concatenates strings |
DAYNAME(date) | Returns the dayname for the given date |
LAST_INSERT_ID( ) | Returns the last record ID inserted |
LENGTH(column) | Returns the length of a string in characters |
TRUNCATE(n,n) | Returns stated number of decimal places |
UNIX_TIMESTAMP( ) | Returns the epoch |
• Some Aggregate Functions | |
AVG(column) | Average number from returned results |
MAX(column) | Returns the largest number from returned results |
MIN(column) | Returns the smallest number from returned results |
SUM(column) | Returns the sum of all returned results |