There are a number of functions in MySQL. for instance SELECT NOW( ) will give just one row, 2012-05-22 09:01:56 with the current date and time. SELECT YEAR(NOW()) will give just one row with the current year, 2012. There are similar function called MONTH and DAY. See http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html for a list of all of the date and time functions. SELECT Version() will tell you what version of MySQL you have.
There are also numeric functions, string functions, and more.
Instead of SELECT *, you can specify which fields to display: SELECT FirstName,LastName FROM Patients (You can add the WHERE and ORDER BY clauses to this.)
The MONTH, DAY and YEAR functions allow you to select a portion of a date field. These functions can be used in any of the clauses:
SELECT * FROM Patients WHERE MONTH(Birthdate)="3" ORDER BY DAY(Birthdate)
This will select everyone who has a birthday in March and order them by the day of their birthday.
SELECT *,YEAR(NOW())-YEAR(Birthdate) AS age FROM Patients This will add a column called age to the display that is calculated by subtracting the year the patient was born from the current year.
The AS clause is important when you want to be able to refer to the created field in PHP. In this case you will be able to refer to that value as $age. (After you have retrieved and extracted the data.)
You can even refer to this name in a later clause of the same expression:
SELECT *,YEAR(NOW())-YEAR(Birthdate) AS age FROM Patients ORDER BY age
It is important to become comfortable with the SELECT expression before continuing.
INDEX, Introduction, Queries, The SELECT query, Functions, Select Fields
Next lesson: MySQL (continued)MAIN INDEX
EXAMPLES INDEX