PHP MySQL Order by Keyword
The ORDER BY
keyword is used to sort the data in a recordset.
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.
The following example creates and populates a Products
table using the following SQL commands:
CREATE TABLE Products (
ID INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(16) NOT NULL );
INSERT INTO Products( name ) VALUES( '$name' );
|
and selects products using the
ORDER BY
operator:
SELECT * FROM Products ORDER BY ID, name;
|