Written by me@grafxflow
12 Mar, 2011
0
2,757
Here are some tips that can really be helpful for MYSQL queries... quick reference.
= |
Equals |
< |
Less than |
<= |
Less than or equal to |
> |
Greater than |
>= |
Greater than or equal to |
<> |
Not equal to |
!= |
Not equal to |
LIKE |
Compare strings |
( ) |
Use parentheses to force precedence |
+ |
add |
- |
subtract |
* |
multiply |
/ |
divide |
% |
modulo |
|| |
Logical "or" |
| |
Bitwise "or" |
OR |
Same as Logical "or" |
&& |
Logical "and" |
& |
Bitwise "and" |
AND |
Same as Logical "and" |
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 |
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 |
USE database |
Selecting a database |
SHOW DATABASES |
Listing databases |
SHOW TABLES |
Listing tables in a db |
DESCRIBE table |
Describing the format of a table |
CREATE DATABASE db_name |
Creating a database |
CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE)); |
Creating a table Example: CREATE TABLE person (name VARCHAR(20), sex CHAR(1), birth DATE) |
SELECT DATABASE() |
Currently selected database |
ALTER TABLE tbl ADD COLUMN [column_create syntax] AFTER col_name |
Adding a column to an already-created table |
ALTER TABLE tbl DROP COLUMN col |
Removing a column |
12 Jan, 2010
08 Nov, 2012
28 Nov, 2012
I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!
Follow11 Jul, 2023
21 Jun, 2023
Views: 166,096
Views: 40,208
Views: 36,920
Views: 33,515