Thứ Ba, 12 tháng 1, 2021

SQL SELECT

Câu lệnh SQL SELECT

Câu lệnh SELECT được sử dụng để chọn dữ liệu từ cơ sở dữ liệu.

Dữ liệu trả về được lưu trữ trong một bảng kết quả, được gọi là tập kết quả.

Cú pháp SELECT

SELECT column1, column2, ...
FROM table_name;

Ở đây, column1, column2, ... là tên trường của bảng mà bạn muốn chọn dữ liệu. Nếu bạn muốn chọn tất cả các trường có sẵn trong bảng, hãy sử dụng cú pháp sau:

SELECT * FROM table_name;

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

Ví dụ về cột SELECT

Câu lệnh SQL sau chọn cột "Tên khách hàng" và "Thành phố" từ bảng "Khách hàng":

Thí dụ

SELECT CustomerName, City FROM Customers;

Result:

Number of Records: 91
CustomerNameCity
Alfreds FutterkisteBerlin
Ana Trujillo Emparedados y heladosMéxico D.F.
Antonio Moreno TaqueríaMéxico D.F.
Around the HornLondon
Berglunds snabbköpLuleå
Blauer See DelikatessenMannheim
Blondel père et filsStrasbourg
Bólido Comidas preparadasMadrid
Bon app'Marseille
Bottom-Dollar MarketseTsawassen
B's BeveragesLondon
Cactus Comidas para llevarBuenos Aires
Centro comercial MoctezumaMéxico D.F.
Chop-suey ChineseBern
Comércio MineiroSão Paulo
Consolidated HoldingsLondon
Drachenblut DelikatessendAachen
Du monde entierNantes
Eastern ConnectionLondon
Ernst HandelGraz
Familia ArquibaldoSão Paulo
FISSA Fabrica Inter. Salchichas S.A.Madrid
Folies gourmandesLille
Folk och fä HBBräcke
FrankenversandMünchen
France restaurationNantes
Franchi S.p.A.Torino
Furia Bacalhau e Frutos do MarLisboa
Galería del gastrónomoBarcelona
Godos Cocina TípicaSevilla
Gourmet LanchonetesCampinas
Great Lakes Food MarketEugene
GROSELLA-RestauranteCaracas
Hanari CarnesRio de Janeiro
HILARIÓN-AbastosSan Cristóbal
Hungry Coyote Import StoreElgin
Hungry Owl All-Night GrocersCork
Island TradingCowes
Königlich EssenBrandenburg
La corne d'abondanceVersailles
La maison d'AsieToulouse
Laughing Bacchus Wine CellarsVancouver
Lazy K Kountry StoreWalla Walla
Lehmanns MarktstandFrankfurt a.M.
Let's Stop N ShopSan Francisco
LILA-SupermercadoBarquisimeto
LINO-DelicatesesI. de Margarita
Lonesome Pine RestaurantPortland
Magazzini Alimentari RiunitiBergamo
Maison DeweyBruxelles
Mère PaillardeMontréal
Morgenstern GesundkostLeipzig
North/SouthLondon
Océano Atlántico Ltda.Buenos Aires
Old World DelicatessenAnchorage
Ottilies KäseladenKöln
Paris spécialitésParis
Pericles Comidas clásicasMéxico D.F.
Piccolo und mehrSalzburg
Princesa Isabel VinhossLisboa
Que DelíciaRio de Janeiro
Queen CozinhaSão Paulo
QUICK-StopCunewalde
Rancho grandeBuenos Aires
Rattlesnake Canyon GroceryAlbuquerque
Reggiani CaseificiReggio Emilia
Ricardo AdocicadosRio de Janeiro
Richter SupermarktGenève
Romero y tomilloMadrid
Santé GourmetStavern
Save-a-lot MarketsBoise
Seven Seas ImportsLondon
Simons bistroKøbenhavn
Spécialités du mondeParis
Split Rail Beer & AleLander
Suprêmes délicesCharleroi
The Big CheesePortland
The Cracker BoxButte
Toms SpezialitätenMünster
Tortuga RestauranteMéxico D.F.
Tradição HipermercadosSão Paulo
Trail's Head Gourmet ProvisionersKirkland
VaffeljernetÅrhus
Victuailles en stockLyon
Vins et alcools ChevalierReims
Die Wandernde KuhStuttgart
Wartian HerkkuOulu
Wellington ImportadoraResende
White Clover MarketsSeattle
Wilman KalaHelsinki
WolskiWalla

SELECT * Ví dụ

Câu lệnh SQL sau chọn tất cả các cột từ bảng "Khách hàng":

Thí dụ

SELECT * FROM Customers;

Result:

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