| AGO | Angola | | AIA | Anguilla | | ALB | Albania | +------+-------------+ 5 rows in set (0.00 sec) 

To specify an order for the results, append the orderBy()  method to the select()  method. Pass to the orderBy()  method a list of one or more columns to sort by and, optionally, the descending ( desc ) or ascending ( asc ) attribute as appropriate. Ascending order is the default order type. 

For example, the following query sorts all records by the Name column and then returns the first three records in descending order . 

mysql-js> db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3) +------+------------+ | Code | Name | +------+------------+ | ZWE | Zimbabwe | | ZMB | Zambia | | YUG | Yugoslavia | +------+------------+ 3 rows in set (0.00 sec) 

By default, the limit()  method starts from the first record in the table. You can use the offset() method to change the starting record. For example, to ignore the first record and return the next three records matching the condition, pass to the offset()  method a value of 1. 

mysql-js> db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3).offset(1) +------+------------+ | Code | Name | +------+------------+ | ZMB | Zambia | | YUG | Yugoslavia | | YEM | Yemen | +------+------------+ 3 rows in set (0.00 sec) 

## Related Information 

•The MySQL Reference Manual provides detailed documentation on functions and operators. 

## 20.3.4.3 Update Tables 

•See TableSelectFunction for the full syntax definition. 

You can use the update()  method to modify one or more records in a table. The update()  method works by filtering a query to include only the records to be updated and then applying the operations you specify to those records. 

To replace a city name in the city table, pass to the set()  method the new city name. Then, pass to the where()  method the city name to locate and replace. The following example replaces the city Peking with Beijing. 

mysql-js> db.city.update().set("Name", "Beijing").where("Name = ’Peking’") 

Use the select()  method to verify the change. 

mysql-js> db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).where("Name = ’Beijing’") +------+-----------+-------------+----------+-----------------------------+ | ID | Name | CountryCode | District | Info | +------+-----------+-------------+----------+-----------------------------+ | 1891 | Beijing | CHN | Peking | {"Population": 7472000} | 

