More on SQL

Updating Information

When updating a field, there are some short cuts.

UPDATE tableName SET field=field+1;

This will increment the field by one if it is a number (INT, BIGINT, etc) data type.

Working with Dates

MySQL has a lot of date functionality built in. Working with dates are very similar across various RDBMS, however each one has their special tricks.

MONTH(fieldName)

This will grab the month from a date field.

SELECT MONTH(birthDay) AS bDayMonth FROM users
DAY(fieldName)

This will grab the day from a date field

SELECT MONTH(birthDay) AS bDayMonth, DAY(birthDay) AS bDayDay FROM users
YEAR(fieldName)

This will grab the year from a date field

SELECT MONTH(birthDay) AS bDayMonth, DAY(birthDay) AS bDayDay, YEAR(birthDay) AS bDayYear FROM users
NOW()

Returns the current time

SELECT NOW()
Other things to know...

Resources:

The Date and Time functions from the mySQL.com website.

INDEX
PREVIOUS
Master Index