Minggu, 04 Mei 2014
BAB 26 PHP MySQL Order By Keyword
BAB 26
PHP MySQL Order By Keyword
________________________________________
The ORDER BY keyword is used to sort the data in a recordset.
Syntax
SELECT column_name(s)
FROM table_name
ORDER BY column_name
Note: SQL statements are not case sensitive. ORDER BY is the same as order by.
Example
The following example selects all the data stored in the "Person" table, and sorts the result by the "Age" column:
";
}
mysql_close($con);
?>
The output of the code above will be:
Glenn Quagmire 33
Peter Griffin 35
________________________________________
Sort Ascending or Descending
If you use the ORDER BY keyword, the sort-order of the recordset is ascending by default (1 before 9 and "a" before "p").
Use the DESC keyword to specify a descending sort-order (9 before 1 and "p" before "a"):
SELECT column_name(s)
FROM table_name
ORDER BY column_name DESC
________________________________________
Order by Two Columns
It is possible to order by more than one column. When ordering by more than one column, the second column is only used if the values in the first column are identical:
SELECT column_name(s)
FROM table_name
ORDER BY column_name1, column_name2
________________________________________
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar