SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname;
执行上面查询,得到以下结果 -
mysql>SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname;+-----------------+------------------+| contactLastname | contactFirstname |+-----------------+------------------+| Accorti | Paolo || Altagar,G M | Raanan || Andersen | Mel || Anton | Carmen || Ashworth | Rachel || Barajas | Miguel || Benitez | Violeta || Bennett | Helen || Berglund | Christina || Bergulfsen | Jonas || Bertrand | Marie |... ....| Young | Julie || Young | Mary || Young | Dorothy |+-----------------+------------------+122rowsinset
SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname DESC;
执行上面查询,得到以下结果 -
mysql>SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname DESC;+-----------------+------------------+| contactLastname | contactFirstname |+-----------------+------------------+| Young | Jeff || Young | Julie || Young | Mary |... ...| Anton | Carmen || Andersen | Mel || Altagar,G M | Raanan || Accorti | Paolo |+-----------------+------------------+122rowsinset
如果要按姓氏按降序和名字按升序排序联系人,请在相应列中分别指定DESC和ASC,如下所示:
SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname DESC, contactFirstname ASC;
执行上面查询,得到以下结果 -
mysql>SELECT contactLastname, contactFirstnameFROM customersORDER BY contactLastname DESC, contactFirstname ASC;+-----------------+------------------+| contactLastname | contactFirstname |+-----------------+------------------+| Young | Dorothy || Young | Jeff || Young | Julie || Young | Mary || Yoshido | Juri || Walker | Brydey || Victorino | Wendy || Urs | Braun || Tseng | Jerry |... ...| Brown | Julie || Brown | William || Bertrand | Marie || Bergulfsen | Jonas || Berglund | Christina || Bennett | Helen || Benitez | Violeta || Barajas | Miguel || Ashworth | Rachel || Anton | Carmen || Andersen | Mel || Altagar,G M | Raanan || Accorti | Paolo |+-----------------+------------------+122rowsinset