Thứ Ba, 12 tháng 1, 2021

SQL ORDER BY

LỆNH SQL THEO Từ khoá

Từ khóa ORDER BY được sử dụng để sắp xếp tập hợp kết quả theo thứ tự tăng dần hoặc giảm dần.

Từ khóa ORDER BY sắp xếp các bản ghi theo thứ tự tăng dần theo mặc định. Để sắp xếp các bản ghi theo thứ tự giảm dần, hãy sử dụng từ khóa DESC.

ORDER BY cú pháp

SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

Cơ sở dữ liệu Demo

Dưới đây là lựa chọn từ bảng "Khách hàng" trong cơ sở dữ liệu mẫu của Northwind:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

ORDER BY Ví dụ

Câu lệnh SQL sau chọn tất cả khách hàng từ bảng "Khách hàng", được sắp xếp theo cột "Quốc gia":

Thí dụ

SELECT * FROM Customers
ORDER BY Country;

Result:

Number of Records: 91
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
12Cactus Comidas para llevarPatricio SimpsonCerrito 333Buenos Aires1010Argentina
54Océano Atlántico Ltda.Yvonne MoncadaIng. Gustavo Moncada 8585 Piso 20-ABuenos Aires1010Argentina
64Rancho grandeSergio GutiérrezAv. del Libertador 900Buenos Aires1010Argentina
20Ernst HandelRoland MendelKirchgasse 6Graz8010Austria
59Piccolo und mehrGeorg PippsGeislweg 14Salzburg5020Austria
50Maison DeweyCatherine DeweyRue Joseph-Bens 532BruxellesB-1180Belgium
76Suprêmes délicesPascale CartrainBoulevard Tirou, 255CharleroiB-6000Belgium
15Comércio MineiroPedro AfonsoAv. dos Lusíadas, 23São Paulo05432-043Brazil
21Familia ArquibaldoAria CruzRua Orós, 92São Paulo05442-030Brazil
31Gourmet LanchonetesAndré FonsecaAv. Brasil, 442Campinas04876-786Brazil
34Hanari CarnesMario PontesRua do Paço, 67Rio de Janeiro05454-876Brazil
61Que DelíciaBernardo BatistaRua da Panificadora, 12Rio de Janeiro02389-673Brazil
62Queen CozinhaLúcia CarvalhoAlameda dos Canàrios, 891São Paulo05487-020Brazil
67Ricardo AdocicadosJanete LimeiraAv. Copacabana, 267Rio de Janeiro02389-890Brazil
81Tradição HipermercadosAnabela DominguesAv. Inês de Castro, 414São Paulo05634-030Brazil
88Wellington ImportadoraPaula ParenteRua do Mercado, 12Resende08737-363Brazil
10Bottom-Dollar MarketseElizabeth Lincoln23 Tsawassen Blvd.TsawassenT2F 8M4Canada
42Laughing Bacchus Wine CellarsYoshi Tannamuri1900 Oak St.VancouverV3F 2K1Canada
51Mère PaillardeJean Fresnière43 rue St. LaurentMontréalH1J 1C3Canada
73Simons bistroJytte PetersenVinbæltet 34København1734Denmark
83VaffeljernetPalle IbsenSmagsløget 45Århus8200Denmark
87Wartian HerkkuPirkko KoskitaloTorikatu 38Oulu90110Finland
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
7Blondel père et filsFrédérique Citeaux24, place KléberStrasbourg67000France
9Bon app'Laurence Lebihans12, rue des BouchersMarseille13008France
18Du monde entierJanine Labrune67, rue des Cinquante OtagesNantes44000France
23Folies gourmandesMartine Rancé184, chaussée de TournaiLille59000France
26France restaurationCarine Schmitt54, rue RoyaleNantes44000France
40La corne d'abondanceDaniel Tonini67, avenue de l'EuropeVersailles78000France
41La maison d'AsieAnnette Roulet1 rue Alsace-LorraineToulouse31000France
57Paris spécialitésMarie Bertrand265, boulevard CharonneParis75012France
74Spécialités du mondeDominique Perrier25, rue LauristonParis75016France
84Victuailles en stockMary Saveley2, rue du CommerceLyon69004France
85Vins et alcools ChevalierPaul Henriot59 rue de l'AbbayeReims51100France
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
6Blauer See DelikatessenHanna MoosForsterstr. 57Mannheim68306Germany
17Drachenblut DelikatessendSven OttliebWalserweg 21Aachen52066Germany
25FrankenversandPeter FrankenBerliner Platz 43München80805Germany
39Königlich EssenPhilip CramerMaubelstr. 90Brandenburg14776Germany
44Lehmanns MarktstandRenate MessnerMagazinweg 7Frankfurt a.M.60528Germany
52Morgenstern GesundkostAlexander FeuerHeerstr. 22Leipzig04179Germany
56Ottilies KäseladenHenriette PfalzheimMehrheimerstr. 369Köln50739Germany
63QUICK-StopHorst KlossTaucherstraße 10Cunewalde01307Germany
79Toms SpezialitätenKarin JosephsLuisenstr. 48Münster44087Germany
86Die Wandernde KuhRita MüllerAdenauerallee 900Stuttgart70563Germany
37Hungry Owl All-Night GrocersPatricia McKenna8 Johnstown RoadCorkIreland
27Franchi S.p.A.Paolo AccortiVia Monte Bianco 34Torino10100Italy
49Magazzini Alimentari RiunitiGiovanni RovelliVia Ludovico il Moro 22Bergamo24100Italy
66Reggiani CaseificiMaurizio MoroniStrada Provinciale 124Reggio Emilia42100Italy
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
13Centro comercial MoctezumaFrancisco ChangSierras de Granada 9993México D.F.05022Mexico
58Pericles Comidas clásicasGuillermo FernándezCalle Dr. Jorge Cash 321México D.F.05033Mexico
80Tortuga RestauranteMiguel Angel PaolinoAvda. Azteca 123México D.F.05033Mexico
70Santé GourmetJonas BergulfsenErling Skakkes gate 78Stavern4110Norway
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
28Furia Bacalhau e Frutos do MarLino RodriguezJardim das rosas n. 32Lisboa1675Portugal
60Princesa Isabel VinhossIsabel de CastroEstrada da saúde n. 58Lisboa1756Portugal
8Bólido Comidas preparadasMartín SommerC/ Araquil, 67Madrid28023Spain
22FISSA Fabrica Inter. Salchichas S.A.Diego RoelC/ Moralzarzal, 86Madrid28034Spain
29Galería del gastrónomoEduardo SaavedraRambla de Cataluña, 23Barcelona08022Spain
30Godos Cocina TípicaJosé Pedro FreyreC/ Romero, 33Sevilla41101Spain
69Romero y tomilloAlejandra CaminoGran Vía, 1Madrid28001Spain
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
24Folk och fä HBMaria LarssonÅkergatan 24BräckeS-844 67Sweden
14Chop-suey ChineseYang WangHauptstr. 29Bern3012Switzerland
68Richter SupermarktMichael HolzGrenzacherweg 237Genève1203Switzerland
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
11B's BeveragesVictoria AshworthFauntleroy CircusLondonEC2 5NTUK
16Consolidated HoldingsElizabeth BrownBerkeley Gardens 12 BreweryLondonWX1 6LTUK
19Eastern ConnectionAnn Devon35 King GeorgeLondonWX3 6FWUK
38Island TradingHelen BennettGarden House Crowther WayCowesPO31 7PJUK
53North/SouthSimon CrowtherSouth House 300 QueensbridgeLondonSW7 1RZUK
72Seven Seas ImportsHari Kumar90 Wadhurst Rd.LondonOX15 4NBUK
32Great Lakes Food MarketHoward Snyder2732 Baker Blvd.Eugene97403USA
36Hungry Coyote Import StoreYoshi LatimerCity Center Plaza 516 Main St.Elgin97827USA
43Lazy K Kountry StoreJohn Steel12 Orchestra TerraceWalla Walla99362USA
45Let's Stop N ShopJaime Yorres87 Polk St. Suite 5San Francisco94117USA
48Lonesome Pine RestaurantFran Wilson89 Chiaroscuro Rd.Portland97219USA
55Old World DelicatessenRene Phillips2743 Bering St.Anchorage99508USA
65Rattlesnake Canyon GroceryPaula Wilson2817 Milton Dr.Albuquerque87110USA
71Save-a-lot MarketsJose Pavarotti187 Suffolk Ln.Boise83720USA
75Split Rail Beer & AleArt BraunschweigerP.O. Box 555Lander82520USA
77The Big CheeseLiz Nixon89 Jefferson Way Suite 2Portland97201USA
78The Cracker BoxLiu Wong55 Grizzly Peak Rd.Butte59801USA
82Trail's Head Gourmet ProvisionersHelvetius Nagy722 DaVinci Blvd.Kirkland98034USA
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
33GROSELLA-RestauranteManuel Pereira5ª Ave. Los Palos GrandesCaracas1081Venezuela
35HILARIÓN-AbastosCarlos HernándezCarrera 22 con Ave. Carlos Soublette #8-35San Cristóbal5022Venezuela
46LILA-SupermercadoCarlos GonzálezCarrera 52 con Ave. Bolívar #65-98 Llano LargoBarquisimeto3508Venezuela
47LINO-DelicatesesFelipe IzquierdoAve. 5 de Mayo PorlamarI. de Margarita4980Venezuela

Ví dụ về ORDER BY DESC

Câu lệnh SQL sau chọn tất cả khách hàng từ bảng "Khách hàng", được sắp xếp MONG MUỐN theo cột "Quốc gia":

Thí dụ

SELECT * FROM Customers
ORDER BY Country DESC;

Result:

Number of Records: 91
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
33GROSELLA-RestauranteManuel Pereira5ª Ave. Los Palos GrandesCaracas1081Venezuela
35HILARIÓN-AbastosCarlos HernándezCarrera 22 con Ave. Carlos Soublette #8-35San Cristóbal5022Venezuela
46LILA-SupermercadoCarlos GonzálezCarrera 52 con Ave. Bolívar #65-98 Llano LargoBarquisimeto3508Venezuela
47LINO-DelicatesesFelipe IzquierdoAve. 5 de Mayo PorlamarI. de Margarita4980Venezuela
32Great Lakes Food MarketHoward Snyder2732 Baker Blvd.Eugene97403USA
36Hungry Coyote Import StoreYoshi LatimerCity Center Plaza 516 Main St.Elgin97827USA
43Lazy K Kountry StoreJohn Steel12 Orchestra TerraceWalla Walla99362USA
45Let's Stop N ShopJaime Yorres87 Polk St. Suite 5San Francisco94117USA
48Lonesome Pine RestaurantFran Wilson89 Chiaroscuro Rd.Portland97219USA
55Old World DelicatessenRene Phillips2743 Bering St.Anchorage99508USA
65Rattlesnake Canyon GroceryPaula Wilson2817 Milton Dr.Albuquerque87110USA
71Save-a-lot MarketsJose Pavarotti187 Suffolk Ln.Boise83720USA
75Split Rail Beer & AleArt BraunschweigerP.O. Box 555Lander82520USA
77The Big CheeseLiz Nixon89 Jefferson Way Suite 2Portland97201USA
78The Cracker BoxLiu Wong55 Grizzly Peak Rd.Butte59801USA
82Trail's Head Gourmet ProvisionersHelvetius Nagy722 DaVinci Blvd.Kirkland98034USA
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
11B's BeveragesVictoria AshworthFauntleroy CircusLondonEC2 5NTUK
16Consolidated HoldingsElizabeth BrownBerkeley Gardens 12 BreweryLondonWX1 6LTUK
19Eastern ConnectionAnn Devon35 King GeorgeLondonWX3 6FWUK
38Island TradingHelen BennettGarden House Crowther WayCowesPO31 7PJUK
53North/SouthSimon CrowtherSouth House 300 QueensbridgeLondonSW7 1RZUK
72Seven Seas ImportsHari Kumar90 Wadhurst Rd.LondonOX15 4NBUK
14Chop-suey ChineseYang WangHauptstr. 29Bern3012Switzerland
68Richter SupermarktMichael HolzGrenzacherweg 237Genève1203Switzerland
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
24Folk och fä HBMaria LarssonÅkergatan 24BräckeS-844 67Sweden
8Bólido Comidas preparadasMartín SommerC/ Araquil, 67Madrid28023Spain
22FISSA Fabrica Inter. Salchichas S.A.Diego RoelC/ Moralzarzal, 86Madrid28034Spain
29Galería del gastrónomoEduardo SaavedraRambla de Cataluña, 23Barcelona08022Spain
30Godos Cocina TípicaJosé Pedro FreyreC/ Romero, 33Sevilla41101Spain
69Romero y tomilloAlejandra CaminoGran Vía, 1Madrid28001Spain
28Furia Bacalhau e Frutos do MarLino RodriguezJardim das rosas n. 32Lisboa1675Portugal
60Princesa Isabel VinhossIsabel de CastroEstrada da saúde n. 58Lisboa1756Portugal
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
70Santé GourmetJonas BergulfsenErling Skakkes gate 78Stavern4110Norway
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
13Centro comercial MoctezumaFrancisco ChangSierras de Granada 9993México D.F.05022Mexico
58Pericles Comidas clásicasGuillermo FernándezCalle Dr. Jorge Cash 321México D.F.05033Mexico
80Tortuga RestauranteMiguel Angel PaolinoAvda. Azteca 123México D.F.05033Mexico
27Franchi S.p.A.Paolo AccortiVia Monte Bianco 34Torino10100Italy
49Magazzini Alimentari RiunitiGiovanni RovelliVia Ludovico il Moro 22Bergamo24100Italy
66Reggiani CaseificiMaurizio MoroniStrada Provinciale 124Reggio Emilia42100Italy
37Hungry Owl All-Night GrocersPatricia McKenna8 Johnstown RoadCorkIreland
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
6Blauer See DelikatessenHanna MoosForsterstr. 57Mannheim68306Germany
17Drachenblut DelikatessendSven OttliebWalserweg 21Aachen52066Germany
25FrankenversandPeter FrankenBerliner Platz 43München80805Germany
39Königlich EssenPhilip CramerMaubelstr. 90Brandenburg14776Germany
44Lehmanns MarktstandRenate MessnerMagazinweg 7Frankfurt a.M.60528Germany
52Morgenstern GesundkostAlexander FeuerHeerstr. 22Leipzig04179Germany
56Ottilies KäseladenHenriette PfalzheimMehrheimerstr. 369Köln50739Germany
63QUICK-StopHorst KlossTaucherstraße 10Cunewalde01307Germany
79Toms SpezialitätenKarin JosephsLuisenstr. 48Münster44087Germany
86Die Wandernde KuhRita MüllerAdenauerallee 900Stuttgart70563Germany
7Blondel père et filsFrédérique Citeaux24, place KléberStrasbourg67000France
9Bon app'Laurence Lebihans12, rue des BouchersMarseille13008France
18Du monde entierJanine Labrune67, rue des Cinquante OtagesNantes44000France
23Folies gourmandesMartine Rancé184, chaussée de TournaiLille59000France
26France restaurationCarine Schmitt54, rue RoyaleNantes44000France
40La corne d'abondanceDaniel Tonini67, avenue de l'EuropeVersailles78000France
41La maison d'AsieAnnette Roulet1 rue Alsace-LorraineToulouse31000France
57Paris spécialitésMarie Bertrand265, boulevard CharonneParis75012France
74Spécialités du mondeDominique Perrier25, rue LauristonParis75016France
84Victuailles en stockMary Saveley2, rue du CommerceLyon69004France
85Vins et alcools ChevalierPaul Henriot59 rue de l'AbbayeReims51100France
87Wartian HerkkuPirkko KoskitaloTorikatu 38Oulu90110Finland
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
73Simons bistroJytte PetersenVinbæltet 34København1734Denmark
83VaffeljernetPalle IbsenSmagsløget 45Århus8200Denmark
10Bottom-Dollar MarketseElizabeth Lincoln23 Tsawassen Blvd.TsawassenT2F 8M4Canada
42Laughing Bacchus Wine CellarsYoshi Tannamuri1900 Oak St.VancouverV3F 2K1Canada
51Mère PaillardeJean Fresnière43 rue St. LaurentMontréalH1J 1C3Canada
15Comércio MineiroPedro AfonsoAv. dos Lusíadas, 23São Paulo05432-043Brazil
21Familia ArquibaldoAria CruzRua Orós, 92São Paulo05442-030Brazil
31Gourmet LanchonetesAndré FonsecaAv. Brasil, 442Campinas04876-786Brazil
34Hanari CarnesMario PontesRua do Paço, 67Rio de Janeiro05454-876Brazil
61Que DelíciaBernardo BatistaRua da Panificadora, 12Rio de Janeiro02389-673Brazil
62Queen CozinhaLúcia CarvalhoAlameda dos Canàrios, 891São Paulo05487-020Brazil
67Ricardo AdocicadosJanete LimeiraAv. Copacabana, 267Rio de Janeiro02389-890Brazil
81Tradição HipermercadosAnabela DominguesAv. Inês de Castro, 414São Paulo05634-030Brazil
88Wellington ImportadoraPaula ParenteRua do Mercado, 12Resende08737-363Brazil
50Maison DeweyCatherine DeweyRue Joseph-Bens 532BruxellesB-1180Belgium
76Suprêmes délicesPascale CartrainBoulevard Tirou, 255CharleroiB-6000Belgium
20Ernst HandelRoland MendelKirchgasse 6Graz8010Austria
59Piccolo und mehrGeorg PippsGeislweg 14Salzburg5020Austria
12Cactus Comidas para llevarPatricio SimpsonCerrito 333Buenos Aires1010Argentina
54Océano Atlántico Ltda.Yvonne MoncadaIng. Gustavo Moncada 8585 Piso 20-ABuenos Aires1010Argentina
64Rancho grandeSergio GutiérrezAv. del Libertador 900Buenos Aires1010Argentina

ORDER BY Một Số Cột Ví dụ

Câu lệnh SQL sau chọn tất cả khách hàng từ bảng "Khách hàng", được sắp xếp theo cột "Quốc gia" và cột "Tên khách hàng". Điều này có nghĩa là nó đặt hàng theo Quốc gia, nhưng nếu một số hàng có cùng Quốc gia, nó sẽ đặt hàng theo CustomerName:

Thí dụ

SELECT * FROM Customers
ORDER BY Country, CustomerName;

Result:

Number of Records: 91
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
12Cactus Comidas para llevarPatricio SimpsonCerrito 333Buenos Aires1010Argentina
54Océano Atlántico Ltda.Yvonne MoncadaIng. Gustavo Moncada 8585 Piso 20-ABuenos Aires1010Argentina
64Rancho grandeSergio GutiérrezAv. del Libertador 900Buenos Aires1010Argentina
20Ernst HandelRoland MendelKirchgasse 6Graz8010Austria
59Piccolo und mehrGeorg PippsGeislweg 14Salzburg5020Austria
50Maison DeweyCatherine DeweyRue Joseph-Bens 532BruxellesB-1180Belgium
76Suprêmes délicesPascale CartrainBoulevard Tirou, 255CharleroiB-6000Belgium
15Comércio MineiroPedro AfonsoAv. dos Lusíadas, 23São Paulo05432-043Brazil
21Familia ArquibaldoAria CruzRua Orós, 92São Paulo05442-030Brazil
31Gourmet LanchonetesAndré FonsecaAv. Brasil, 442Campinas04876-786Brazil
34Hanari CarnesMario PontesRua do Paço, 67Rio de Janeiro05454-876Brazil
61Que DelíciaBernardo BatistaRua da Panificadora, 12Rio de Janeiro02389-673Brazil
62Queen CozinhaLúcia CarvalhoAlameda dos Canàrios, 891São Paulo05487-020Brazil
67Ricardo AdocicadosJanete LimeiraAv. Copacabana, 267Rio de Janeiro02389-890Brazil
81Tradição HipermercadosAnabela DominguesAv. Inês de Castro, 414São Paulo05634-030Brazil
88Wellington ImportadoraPaula ParenteRua do Mercado, 12Resende08737-363Brazil
10Bottom-Dollar MarketseElizabeth Lincoln23 Tsawassen Blvd.TsawassenT2F 8M4Canada
42Laughing Bacchus Wine CellarsYoshi Tannamuri1900 Oak St.VancouverV3F 2K1Canada
51Mère PaillardeJean Fresnière43 rue St. LaurentMontréalH1J 1C3Canada
73Simons bistroJytte PetersenVinbæltet 34København1734Denmark
83VaffeljernetPalle IbsenSmagsløget 45Århus8200Denmark
87Wartian HerkkuPirkko KoskitaloTorikatu 38Oulu90110Finland
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
7Blondel père et filsFrédérique Citeaux24, place KléberStrasbourg67000France
9Bon app'Laurence Lebihans12, rue des BouchersMarseille13008France
18Du monde entierJanine Labrune67, rue des Cinquante OtagesNantes44000France
23Folies gourmandesMartine Rancé184, chaussée de TournaiLille59000France
26France restaurationCarine Schmitt54, rue RoyaleNantes44000France
40La corne d'abondanceDaniel Tonini67, avenue de l'EuropeVersailles78000France
41La maison d'AsieAnnette Roulet1 rue Alsace-LorraineToulouse31000France
57Paris spécialitésMarie Bertrand265, boulevard CharonneParis75012France
74Spécialités du mondeDominique Perrier25, rue LauristonParis75016France
84Victuailles en stockMary Saveley2, rue du CommerceLyon69004France
85Vins et alcools ChevalierPaul Henriot59 rue de l'AbbayeReims51100France
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
6Blauer See DelikatessenHanna MoosForsterstr. 57Mannheim68306Germany
86Die Wandernde KuhRita MüllerAdenauerallee 900Stuttgart70563Germany
17Drachenblut DelikatessendSven OttliebWalserweg 21Aachen52066Germany
25FrankenversandPeter FrankenBerliner Platz 43München80805Germany
39Königlich EssenPhilip CramerMaubelstr. 90Brandenburg14776Germany
44Lehmanns MarktstandRenate MessnerMagazinweg 7Frankfurt a.M.60528Germany
52Morgenstern GesundkostAlexander FeuerHeerstr. 22Leipzig04179Germany
56Ottilies KäseladenHenriette PfalzheimMehrheimerstr. 369Köln50739Germany
63QUICK-StopHorst KlossTaucherstraße 10Cunewalde01307Germany
79Toms SpezialitätenKarin JosephsLuisenstr. 48Münster44087Germany
37Hungry Owl All-Night GrocersPatricia McKenna8 Johnstown RoadCorkIreland
27Franchi S.p.A.Paolo AccortiVia Monte Bianco 34Torino10100Italy
49Magazzini Alimentari RiunitiGiovanni RovelliVia Ludovico il Moro 22Bergamo24100Italy
66Reggiani CaseificiMaurizio MoroniStrada Provinciale 124Reggio Emilia42100Italy
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
13Centro comercial MoctezumaFrancisco ChangSierras de Granada 9993México D.F.05022Mexico
58Pericles Comidas clásicasGuillermo FernándezCalle Dr. Jorge Cash 321México D.F.05033Mexico
80Tortuga RestauranteMiguel Angel PaolinoAvda. Azteca 123México D.F.05033Mexico
70Santé GourmetJonas BergulfsenErling Skakkes gate 78Stavern4110Norway
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
28Furia Bacalhau e Frutos do MarLino RodriguezJardim das rosas n. 32Lisboa1675Portugal
60Princesa Isabel VinhossIsabel de CastroEstrada da saúde n. 58Lisboa1756Portugal
8Bólido Comidas preparadasMartín SommerC/ Araquil, 67Madrid28023Spain
22FISSA Fabrica Inter. Salchichas S.A.Diego RoelC/ Moralzarzal, 86Madrid28034Spain
29Galería del gastrónomoEduardo SaavedraRambla de Cataluña, 23Barcelona08022Spain
30Godos Cocina TípicaJosé Pedro FreyreC/ Romero, 33Sevilla41101Spain
69Romero y tomilloAlejandra CaminoGran Vía, 1Madrid28001Spain
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
24Folk och fä HBMaria LarssonÅkergatan 24BräckeS-844 67Sweden
14Chop-suey ChineseYang WangHauptstr. 29Bern3012Switzerland
68Richter SupermarktMichael HolzGrenzacherweg 237Genève1203Switzerland
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
11B's BeveragesVictoria AshworthFauntleroy CircusLondonEC2 5NTUK
16Consolidated HoldingsElizabeth BrownBerkeley Gardens 12 BreweryLondonWX1 6LTUK
19Eastern ConnectionAnn Devon35 King GeorgeLondonWX3 6FWUK
38Island TradingHelen BennettGarden House Crowther WayCowesPO31 7PJUK
53North/SouthSimon CrowtherSouth House 300 QueensbridgeLondonSW7 1RZUK
72Seven Seas ImportsHari Kumar90 Wadhurst Rd.LondonOX15 4NBUK
32Great Lakes Food MarketHoward Snyder2732 Baker Blvd.Eugene97403USA
36Hungry Coyote Import StoreYoshi LatimerCity Center Plaza 516 Main St.Elgin97827USA
43Lazy K Kountry StoreJohn Steel12 Orchestra TerraceWalla Walla99362USA
45Let's Stop N ShopJaime Yorres87 Polk St. Suite 5San Francisco94117USA
48Lonesome Pine RestaurantFran Wilson89 Chiaroscuro Rd.Portland97219USA
55Old World DelicatessenRene Phillips2743 Bering St.Anchorage99508USA
65Rattlesnake Canyon GroceryPaula Wilson2817 Milton Dr.Albuquerque87110USA
71Save-a-lot MarketsJose Pavarotti187 Suffolk Ln.Boise83720USA
75Split Rail Beer & AleArt BraunschweigerP.O. Box 555Lander82520USA
77The Big CheeseLiz Nixon89 Jefferson Way Suite 2Portland97201USA
78The Cracker BoxLiu Wong55 Grizzly Peak Rd.Butte59801USA
82Trail's Head Gourmet ProvisionersHelvetius Nagy722 DaVinci Blvd.Kirkland98034USA
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
33GROSELLA-RestauranteManuel Pereira5ª Ave. Los Palos GrandesCaracas1081Venezuela
35HILARIÓN-AbastosCarlos HernándezCarrera 22 con Ave. Carlos Soublette #8-35San Cristóbal5022Venezuela
46LILA-SupermercadoCarlos GonzálezCarrera 52 con Ave. Bolívar #65-98 Llano LargoBarquisimeto3508Venezuela
47LINO-DelicatesesFelipe IzquierdoAve. 5 de Mayo PorlamarI. de Margarita4980Venezuela

ORDER BY Một Số Cột Ví dụ 2

Câu lệnh SQL sau chọn tất cả khách hàng từ bảng "Khách hàng", được sắp xếp tăng dần theo "Quốc gia" và giảm dần theo cột "Tên khách hàng":

Thí dụ

SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;

Result:

Number of Records: 91
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
64Rancho grandeSergio GutiérrezAv. del Libertador 900Buenos Aires1010Argentina
54Océano Atlántico Ltda.Yvonne MoncadaIng. Gustavo Moncada 8585 Piso 20-ABuenos Aires1010Argentina
12Cactus Comidas para llevarPatricio SimpsonCerrito 333Buenos Aires1010Argentina
59Piccolo und mehrGeorg PippsGeislweg 14Salzburg5020Austria
20Ernst HandelRoland MendelKirchgasse 6Graz8010Austria
76Suprêmes délicesPascale CartrainBoulevard Tirou, 255CharleroiB-6000Belgium
50Maison DeweyCatherine DeweyRue Joseph-Bens 532BruxellesB-1180Belgium
88Wellington ImportadoraPaula ParenteRua do Mercado, 12Resende08737-363Brazil
81Tradição HipermercadosAnabela DominguesAv. Inês de Castro, 414São Paulo05634-030Brazil
67Ricardo AdocicadosJanete LimeiraAv. Copacabana, 267Rio de Janeiro02389-890Brazil
62Queen CozinhaLúcia CarvalhoAlameda dos Canàrios, 891São Paulo05487-020Brazil
61Que DelíciaBernardo BatistaRua da Panificadora, 12Rio de Janeiro02389-673Brazil
34Hanari CarnesMario PontesRua do Paço, 67Rio de Janeiro05454-876Brazil
31Gourmet LanchonetesAndré FonsecaAv. Brasil, 442Campinas04876-786Brazil
21Familia ArquibaldoAria CruzRua Orós, 92São Paulo05442-030Brazil
15Comércio MineiroPedro AfonsoAv. dos Lusíadas, 23São Paulo05432-043Brazil
51Mère PaillardeJean Fresnière43 rue St. LaurentMontréalH1J 1C3Canada
42Laughing Bacchus Wine CellarsYoshi Tannamuri1900 Oak St.VancouverV3F 2K1Canada
10Bottom-Dollar MarketseElizabeth Lincoln23 Tsawassen Blvd.TsawassenT2F 8M4Canada
83VaffeljernetPalle IbsenSmagsløget 45Århus8200Denmark
73Simons bistroJytte PetersenVinbæltet 34København1734Denmark
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
87Wartian HerkkuPirkko KoskitaloTorikatu 38Oulu90110Finland
85Vins et alcools ChevalierPaul Henriot59 rue de l'AbbayeReims51100France
84Victuailles en stockMary Saveley2, rue du CommerceLyon69004France
74Spécialités du mondeDominique Perrier25, rue LauristonParis75016France
57Paris spécialitésMarie Bertrand265, boulevard CharonneParis75012France
41La maison d'AsieAnnette Roulet1 rue Alsace-LorraineToulouse31000France
40La corne d'abondanceDaniel Tonini67, avenue de l'EuropeVersailles78000France
26France restaurationCarine Schmitt54, rue RoyaleNantes44000France
23Folies gourmandesMartine Rancé184, chaussée de TournaiLille59000France
18Du monde entierJanine Labrune67, rue des Cinquante OtagesNantes44000France
9Bon app'Laurence Lebihans12, rue des BouchersMarseille13008France
7Blondel père et filsFrédérique Citeaux24, place KléberStrasbourg67000France
79Toms SpezialitätenKarin JosephsLuisenstr. 48Münster44087Germany
63QUICK-StopHorst KlossTaucherstraße 10Cunewalde01307Germany
56Ottilies KäseladenHenriette PfalzheimMehrheimerstr. 369Köln50739Germany
52Morgenstern GesundkostAlexander FeuerHeerstr. 22Leipzig04179Germany
44Lehmanns MarktstandRenate MessnerMagazinweg 7Frankfurt a.M.60528Germany
39Königlich EssenPhilip CramerMaubelstr. 90Brandenburg14776Germany
25FrankenversandPeter FrankenBerliner Platz 43München80805Germany
17Drachenblut DelikatessendSven OttliebWalserweg 21Aachen52066Germany
86Die Wandernde KuhRita MüllerAdenauerallee 900Stuttgart70563Germany
6Blauer See DelikatessenHanna MoosForsterstr. 57Mannheim68306Germany
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
37Hungry Owl All-Night GrocersPatricia McKenna8 Johnstown RoadCorkIreland
66Reggiani CaseificiMaurizio MoroniStrada Provinciale 124Reggio Emilia42100Italy
49Magazzini Alimentari RiunitiGiovanni RovelliVia Ludovico il Moro 22Bergamo24100Italy
27Franchi S.p.A.Paolo AccortiVia Monte Bianco 34Torino10100Italy
80Tortuga RestauranteMiguel Angel PaolinoAvda. Azteca 123México D.F.05033Mexico
58Pericles Comidas clásicasGuillermo FernándezCalle Dr. Jorge Cash 321México D.F.05033Mexico
13Centro comercial MoctezumaFrancisco ChangSierras de Granada 9993México D.F.05022Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
70Santé GourmetJonas BergulfsenErling Skakkes gate 78Stavern4110Norway
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
60Princesa Isabel VinhossIsabel de CastroEstrada da saúde n. 58Lisboa1756Portugal
28Furia Bacalhau e Frutos do MarLino RodriguezJardim das rosas n. 32Lisboa1675Portugal
69Romero y tomilloAlejandra CaminoGran Vía, 1Madrid28001Spain
30Godos Cocina TípicaJosé Pedro FreyreC/ Romero, 33Sevilla41101Spain
29Galería del gastrónomoEduardo SaavedraRambla de Cataluña, 23Barcelona08022Spain
22FISSA Fabrica Inter. Salchichas S.A.Diego RoelC/ Moralzarzal, 86Madrid28034Spain
8Bólido Comidas preparadasMartín SommerC/ Araquil, 67Madrid28023Spain
24Folk och fä HBMaria LarssonÅkergatan 24BräckeS-844 67Sweden
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
68Richter SupermarktMichael HolzGrenzacherweg 237Genève1203Switzerland
14Chop-suey ChineseYang WangHauptstr. 29Bern3012Switzerland
72Seven Seas ImportsHari Kumar90 Wadhurst Rd.LondonOX15 4NBUK
53North/SouthSimon CrowtherSouth House 300 QueensbridgeLondonSW7 1RZUK
38Island TradingHelen BennettGarden House Crowther WayCowesPO31 7PJUK
19Eastern ConnectionAnn Devon35 King GeorgeLondonWX3 6FWUK
16Consolidated HoldingsElizabeth BrownBerkeley Gardens 12 BreweryLondonWX1 6LTUK
11B's BeveragesVictoria AshworthFauntleroy CircusLondonEC2 5NTUK
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
82Trail's Head Gourmet ProvisionersHelvetius Nagy722 DaVinci Blvd.Kirkland98034USA
78The Cracker BoxLiu Wong55 Grizzly Peak Rd.Butte59801USA
77The Big CheeseLiz Nixon89 Jefferson Way Suite 2Portland97201USA
75Split Rail Beer & AleArt BraunschweigerP.O. Box 555Lander82520USA
71Save-a-lot MarketsJose Pavarotti187 Suffolk Ln.Boise83720USA
65Rattlesnake Canyon GroceryPaula Wilson2817 Milton Dr.Albuquerque87110USA
55Old World DelicatessenRene Phillips2743 Bering St.Anchorage99508USA
48Lonesome Pine RestaurantFran Wilson89 Chiaroscuro Rd.Portland97219USA
45Let's Stop N ShopJaime Yorres87 Polk St. Suite 5San Francisco94117USA
43Lazy K Kountry StoreJohn Steel12 Orchestra TerraceWalla Walla99362USA
36Hungry Coyote Import StoreYoshi LatimerCity Center Plaza 516 Main St.Elgin97827USA
32Great Lakes Food MarketHoward Snyder2732 Baker Blvd.Eugene97403USA
47LINO-DelicatesesFelipe IzquierdoAve. 5 de Mayo PorlamarI. de Margarita4980Venezuela
46LILA-SupermercadoCarlos GonzálezCarrera 52 con Ave. Bolívar #65-98 Llano LargoBarquisimeto3508Venezuela
35HILARIÓN-AbastosCarlos HernándezCarrera 22 con Ave. Carlos Soublette #8-35San Cristóbal5022Venezuela
33GROSELLA-RestauranteManuel Pereira5ª Ave. Los Palos GrandesCaracas1081Venezuela
==================================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile: 0902912888
⚡️ Skype: tranbinh48ca
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

#OracleTutorial #OracleDBA #OracleDatabaseAdministration #học oracle database #oca #ocp #tự học oracle

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master