The data retrieved from a selected table is based on the sequence of the data entered into the table. Therefore, the data may not be in any order based on the context. Figure 1 below shows the retrieval of data from the table students.
|
Figure 1: Table students |
Noted that the data is not sorted by name or by year of intake and only based on the primary key (stdid). Database administrator or user can choose to order the data based on the column desired. The syntax to perform the operation is:
Database administrator or user can choose which column to sort and also how to sort the data.
ASC is the keyword to sort the data in an ascending order (small to big), while
DESC is the keyword to sort the data in a descending order. The example of sorting using
ASC keyword is shown in Figure 2, while the example of sorting data using
DESC keyword is shown in Figure 3.
|
Figure 2: Sorting the data from students table based on column stdname in ascending order.
|
|
Figure 3: Sorting the data from students table based on column stdname in descending order. |