MySQL Icon Logo
me@grafxflow

Written by me@grafxflow

12 Mar, 2011

0

2,757

MySQL Function Tips

Here are some tips that can really be helpful for MYSQL queries... quick reference.

 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

 Database control functions

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

Add comment

Smart Search

133 Following
50 Followers

me@grafxflow

Hull, United Kingdom

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!

Follow