Alias
테이블 또는 테이블의 열을 임시 이름으로 지정하는 데 사용된다.
별칭은 종종 열 이름을 더 읽기 쉽게 만드는 데 사용된다.
별칭은 해당 쿼리 기간 동안만 존재한다.
별칭은 AS 키워드로 만들어진다.
구문 – 열 별칭 지정
SELECT column_name AS alias_name FROM table_name;
구문 – 테이블 별칭 지정
SELECT column_name(s) FROM table_name AS alias_name;
데이터베이스 예시
고객 테이블 예시
CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|---|
2 | Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitución 2222 | México D.F. | 05021 | Mexico |
3 | Antonio Moreno Taquería | Antonio Moreno | Mataderos 2312 | México D.F. | 05023 | Mexico |
4 | Around the Horn | Thomas Hardy | 120 Hanover Sq. | London | WA1 1DP | UK |
주문 테이블 예시
OrderID | CustomerID | EmployeeID | OrderDate | ShipperID |
---|---|---|---|---|
10354 | 58 | 8 | 1996-11-14 | 3 |
10355 | 4 | 6 | 1996-11-15 | 1 |
10356 | 86 | 6 | 1996-11-18 | 2 |
CustomerID 열용이고 다른 하나는 CustomerName 열에 대한 별칭 지정
SELECT CustomerID AS ID, CustomerName AS Customer FROM Customers;
기본 예시
ID | Customer |
---|---|
1 | Alfreds Futterkiste |
2 | Ana Trujillo Emparedados y helados |
3 | Antonio Moreno Taquería |
4 | Around the Horn |
5 | Berglunds snabbköp |
6 | Blauer See Delikatessen |
7 | Blondel père et fils |
8 | Bólido Comidas preparadas |
9 | Bon app’ |
10 | Bottom-Dollar Marketse |
11 | B’s Beverages |
12 | Cactus Comidas para llevar |
13 | Centro comercial Moctezuma |
14 | Chop-suey Chinese |
15 | Comércio Mineiro |
16 | Consolidated Holdings |
17 | Drachenblut Delikatessend |
18 | Du monde entier |
19 | Eastern Connection |
20 | Ernst Handel |
21 | Familia Arquibaldo |
22 | FISSA Fabrica Inter. Salchichas S.A. |
23 | Folies gourmandes |
24 | Folk och fä HB |
25 | Frankenversand |
26 | France restauration |
27 | Franchi S.p.A. |
28 | Furia Bacalhau e Frutos do Mar |
29 | Galería del gastrónomo |
30 | Godos Cocina Típica |
31 | Gourmet Lanchonetes |
32 | Great Lakes Food Market |
33 | GROSELLA-Restaurante |
34 | Hanari Carnes |
35 | HILARIÓN-Abastos |
36 | Hungry Coyote Import Store |
37 | Hungry Owl All-Night Grocers |
38 | Island Trading |
39 | Königlich Essen |
40 | La corne d’abondance |
41 | La maison d’Asie |
42 | Laughing Bacchus Wine Cellars |
43 | Lazy K Kountry Store |
44 | Lehmanns Marktstand |
45 | Let’s Stop N Shop |
46 | LILA-Supermercado |
47 | LINO-Delicateses |
48 | Lonesome Pine Restaurant |
49 | Magazzini Alimentari Riuniti |
50 | Maison Dewey |
51 | Mère Paillarde |
52 | Morgenstern Gesundkost |
53 | North/South |
54 | Océano Atlántico Ltda. |
55 | Old World Delicatessen |
56 | Ottilies Käseladen |
57 | Paris spécialités |
58 | Pericles Comidas clásicas |
59 | Piccolo und mehr |
60 | Princesa Isabel Vinhoss |
61 | Que Delícia |
62 | Queen Cozinha |
63 | QUICK-Stop |
64 | Rancho grande |
65 | Rattlesnake Canyon Grocery |
66 | Reggiani Caseifici |
67 | Ricardo Adocicados |
68 | Richter Supermarkt |
69 | Romero y tomillo |
70 | Santé Gourmet |
71 | Save-a-lot Markets |
72 | Seven Seas Imports |
73 | Simons bistro |
74 | Spécialités du monde |
75 | Split Rail Beer & Ale |
76 | Suprêmes délices |
77 | The Big Cheese |
78 | The Cracker Box |
79 | Toms Spezialitäten |
80 | Tortuga Restaurante |
81 | Tradição Hipermercados |
82 | Trail’s Head Gourmet Provisioners |
83 | Vaffeljernet |
84 | Victuailles en stock |
85 | Vins et alcools Chevalier |
86 | Die Wandernde Kuh |
87 | Wartian Herkku |
88 | Wellington Importadora |
89 | White Clover Markets |
90 | Wilman Kala |
91 | Wolski |
CustomerName 열용이고 다른 하나는 ContactName 열에 대한 별칭 지정
⭐ 별칭 이름에 공백이 포함된 경우 큰따옴표 또는 대괄호가 필요하다.
SELECT CustomerName AS Customer, ContactName AS [Contact Person] FROM Customers;
기본 예시
Customer | Contact Person |
---|---|
Alfreds Futterkiste | Maria Anders |
Ana Trujillo Emparedados y helados | Ana Trujillo |
Antonio Moreno Taquería | Antonio Moreno |
Around the Horn | Thomas Hardy |
Berglunds snabbköp | Christina Berglund |
Blauer See Delikatessen | Hanna Moos |
Blondel père et fils | Frédérique Citeaux |
Bólido Comidas preparadas | Martín Sommer |
Bon app’ | Laurence Lebihans |
Bottom-Dollar Marketse | Elizabeth Lincoln |
B’s Beverages | Victoria Ashworth |
Cactus Comidas para llevar | Patricio Simpson |
Centro comercial Moctezuma | Francisco Chang |
Chop-suey Chinese | Yang Wang |
Comércio Mineiro | Pedro Afonso |
Consolidated Holdings | Elizabeth Brown |
Drachenblut Delikatessend | Sven Ottlieb |
Du monde entier | Janine Labrune |
Eastern Connection | Ann Devon |
Ernst Handel | Roland Mendel |
Familia Arquibaldo | Aria Cruz |
FISSA Fabrica Inter. Salchichas S.A. | Diego Roel |
Folies gourmandes | Martine Rancé |
Folk och fä HB | Maria Larsson |
Frankenversand | Peter Franken |
France restauration | Carine Schmitt |
Franchi S.p.A. | Paolo Accorti |
Furia Bacalhau e Frutos do Mar | Lino Rodriguez |
Galería del gastrónomo | Eduardo Saavedra |
Godos Cocina Típica | José Pedro Freyre |
Gourmet Lanchonetes | André Fonseca |
Great Lakes Food Market | Howard Snyder |
GROSELLA-Restaurante | Manuel Pereira |
Hanari Carnes | Mario Pontes |
HILARIÓN-Abastos | Carlos Hernández |
Hungry Coyote Import Store | Yoshi Latimer |
Hungry Owl All-Night Grocers | Patricia McKenna |
Island Trading | Helen Bennett |
Königlich Essen | Philip Cramer |
La corne d’abondance | Daniel Tonini |
La maison d’Asie | Annette Roulet |
Laughing Bacchus Wine Cellars | Yoshi Tannamuri |
Lazy K Kountry Store | John Steel |
Lehmanns Marktstand | Renate Messner |
Let’s Stop N Shop | Jaime Yorres |
LILA-Supermercado | Carlos González |
LINO-Delicateses | Felipe Izquierdo |
Lonesome Pine Restaurant | Fran Wilson |
Magazzini Alimentari Riuniti | Giovanni Rovelli |
Maison Dewey | Catherine Dewey |
Mère Paillarde | Jean Fresnière |
Morgenstern Gesundkost | Alexander Feuer |
North/South | Simon Crowther |
Océano Atlántico Ltda. | Yvonne Moncada |
Old World Delicatessen | Rene Phillips |
Ottilies Käseladen | Henriette Pfalzheim |
Paris spécialités | Marie Bertrand |
Pericles Comidas clásicas | Guillermo Fernández |
Piccolo und mehr | Georg Pipps |
Princesa Isabel Vinhoss | Isabel de Castro |
Que Delícia | Bernardo Batista |
Queen Cozinha | Lúcia Carvalho |
QUICK-Stop | Horst Kloss |
Rancho grande | Sergio Gutiérrez |
Rattlesnake Canyon Grocery | Paula Wilson |
Reggiani Caseifici | Maurizio Moroni |
Ricardo Adocicados | Janete Limeira |
Richter Supermarkt | Michael Holz |
Romero y tomillo | Alejandra Camino |
Santé Gourmet | Jonas Bergulfsen |
Save-a-lot Markets | Jose Pavarotti |
Seven Seas Imports | Hari Kumar |
Simons bistro | Jytte Petersen |
Spécialités du monde | Dominique Perrier |
Split Rail Beer & Ale | Art Braunschweiger |
Suprêmes délices | Pascale Cartrain |
The Big Cheese | Liz Nixon |
The Cracker Box | Liu Wong |
Toms Spezialitäten | Karin Josephs |
Tortuga Restaurante | Miguel Angel Paolino |
Tradição Hipermercados | Anabela Domingues |
Trail’s Head Gourmet Provisioners | Helvetius Nagy |
Vaffeljernet | Palle Ibsen |
Victuailles en stock | Mary Saveley |
Vins et alcools Chevalier | Paul Henriot |
Die Wandernde Kuh | Rita Müller |
Wartian Herkku | Pirkko Koskitalo |
Wellington Importadora | Paula Parente |
White Clover Markets | Karl Jablonski |
Wilman Kala | Matti Karttunen |
Wolski | Zbyszek |
네 개의 열(주소, 우편 번호, 도시 및 국가)을 결합하는 “주소”라는 별칭 지정
표준 SQL 쿼리
SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address FROM Customers;
MySQL
SELECT CustomerName, CONCAT(Address,', ',PostalCode,', ',City,', ',Country) AS Address FROM Customers;
Oracle
SELECT CustomerName, (Address || ', ' || PostalCode || ' ' || City || ', ' || Country) AS Address FROM Customers;
기본 예시
CustomerName | Address |
---|---|
Alfreds Futterkiste | Obere Str. 57, 12209 Berlin, Germany |
Ana Trujillo Emparedados y helados | Avda. de la Constitución 2222, 05021 México D.F., Mexico |
Antonio Moreno Taquería | Mataderos 2312, 05023 México D.F., Mexico |
Around the Horn | 120 Hanover Sq., WA1 1DP London, UK |
Berglunds snabbköp | Berguvsvägen 8, S-958 22 Luleå, Sweden |
Blauer See Delikatessen | Forsterstr. 57, 68306 Mannheim, Germany |
Blondel père et fils | 24, place Kléber, 67000 Strasbourg, France |
Bólido Comidas preparadas | C/ Araquil, 67, 28023 Madrid, Spain |
Bon app’ | 12, rue des Bouchers, 13008 Marseille, France |
Bottom-Dollar Marketse | 23 Tsawassen Blvd., T2F 8M4 Tsawassen, Canada |
B’s Beverages | Fauntleroy Circus, EC2 5NT London, UK |
Cactus Comidas para llevar | Cerrito 333, 1010 Buenos Aires, Argentina |
Centro comercial Moctezuma | Sierras de Granada 9993, 05022 México D.F., Mexico |
Chop-suey Chinese | Hauptstr. 29, 3012 Bern, Switzerland |
Comércio Mineiro | Av. dos Lusíadas, 23, 05432-043 São Paulo, Brazil |
Consolidated Holdings | Berkeley Gardens 12 Brewery , WX1 6LT London, UK |
Drachenblut Delikatessend | Walserweg 21, 52066 Aachen, Germany |
Du monde entier | 67, rue des Cinquante Otages, 44000 Nantes, France |
Eastern Connection | 35 King George, WX3 6FW London, UK |
Ernst Handel | Kirchgasse 6, 8010 Graz, Austria |
Familia Arquibaldo | Rua Orós, 92, 05442-030 São Paulo, Brazil |
FISSA Fabrica Inter. Salchichas S.A. | C/ Moralzarzal, 86, 28034 Madrid, Spain |
Folies gourmandes | 184, chaussée de Tournai, 59000 Lille, France |
Folk och fä HB | Åkergatan 24, S-844 67 Bräcke, Sweden |
Frankenversand | Berliner Platz 43, 80805 München, Germany |
France restauration | 54, rue Royale, 44000 Nantes, France |
Franchi S.p.A. | Via Monte Bianco 34, 10100 Torino, Italy |
Furia Bacalhau e Frutos do Mar | Jardim das rosas n. 32, 1675 Lisboa, Portugal |
Galería del gastrónomo | Rambla de Cataluña, 23, 08022 Barcelona, Spain |
Godos Cocina Típica | C/ Romero, 33, 41101 Sevilla, Spain |
Gourmet Lanchonetes | Av. Brasil, 442, 04876-786 Campinas, Brazil |
Great Lakes Food Market | 2732 Baker Blvd., 97403 Eugene, USA |
GROSELLA-Restaurante | 5ª Ave. Los Palos Grandes, 1081 Caracas, Venezuela |
Hanari Carnes | Rua do Paço, 67, 05454-876 Rio de Janeiro, Brazil |
HILARIÓN-Abastos | Carrera 22 con Ave. Carlos Soublette #8-35, 5022 San Cristóbal, Venezuela |
Hungry Coyote Import Store | City Center Plaza 516 Main St., 97827 Elgin, USA |
Hungry Owl All-Night Grocers | 8 Johnstown Road, Cork, Ireland |
Island Trading | Garden House Crowther Way, PO31 7PJ Cowes, UK |
Königlich Essen | Maubelstr. 90, 14776 Brandenburg, Germany |
La corne d’abondance | 67, avenue de l’Europe, 78000 Versailles, France |
La maison d’Asie | 1 rue Alsace-Lorraine, 31000 Toulouse, France |
Laughing Bacchus Wine Cellars | 1900 Oak St., V3F 2K1 Vancouver, Canada |
Lazy K Kountry Store | 12 Orchestra Terrace, 99362 Walla Walla, USA |
Lehmanns Marktstand | Magazinweg 7, 60528 Frankfurt a.M. , Germany |
Let’s Stop N Shop | 87 Polk St. Suite 5, 94117 San Francisco, USA |
LILA-Supermercado | Carrera 52 con Ave. Bolívar #65-98 Llano Largo, 3508 Barquisimeto, Venezuela |
LINO-Delicateses | Ave. 5 de Mayo Porlamar, 4980 I. de Margarita, Venezuela |
Lonesome Pine Restaurant | 89 Chiaroscuro Rd., 97219 Portland, USA |
Magazzini Alimentari Riuniti | Via Ludovico il Moro 22, 24100 Bergamo, Italy |
Maison Dewey | Rue Joseph-Bens 532, B-1180 Bruxelles, Belgium |
Mère Paillarde | 43 rue St. Laurent, H1J 1C3 Montréal, Canada |
Morgenstern Gesundkost | Heerstr. 22, 04179 Leipzig, Germany |
North/South | South House 300 Queensbridge, SW7 1RZ London, UK |
Océano Atlántico Ltda. | Ing. Gustavo Moncada 8585 Piso 20-A, 1010 Buenos Aires, Argentina |
Old World Delicatessen | 2743 Bering St., 99508 Anchorage, USA |
Ottilies Käseladen | Mehrheimerstr. 369, 50739 Köln, Germany |
Paris spécialités | 265, boulevard Charonne, 75012 Paris, France |
Pericles Comidas clásicas | Calle Dr. Jorge Cash 321, 05033 México D.F., Mexico |
Piccolo und mehr | Geislweg 14, 5020 Salzburg, Austria |
Princesa Isabel Vinhoss | Estrada da saúde n. 58, 1756 Lisboa, Portugal |
Que Delícia | Rua da Panificadora, 12, 02389-673 Rio de Janeiro, Brazil |
Queen Cozinha | Alameda dos Canàrios, 891, 05487-020 São Paulo, Brazil |
QUICK-Stop | Taucherstraße 10, 01307 Cunewalde, Germany |
Rancho grande | Av. del Libertador 900, 1010 Buenos Aires, Argentina |
Rattlesnake Canyon Grocery | 2817 Milton Dr., 87110 Albuquerque, USA |
Reggiani Caseifici | Strada Provinciale 124, 42100 Reggio Emilia, Italy |
Ricardo Adocicados | Av. Copacabana, 267, 02389-890 Rio de Janeiro, Brazil |
Richter Supermarkt | Grenzacherweg 237, 1203 Genève, Switzerland |
Romero y tomillo | Gran Vía, 1, 28001 Madrid, Spain |
Santé Gourmet | Erling Skakkes gate 78, 4110 Stavern, Norway |
Save-a-lot Markets | 187 Suffolk Ln., 83720 Boise, USA |
Seven Seas Imports | 90 Wadhurst Rd., OX15 4NB London, UK |
Simons bistro | Vinbæltet 34, 1734 København, Denmark |
Spécialités du monde | 25, rue Lauriston, 75016 Paris, France |
Split Rail Beer & Ale | P.O. Box 555, 82520 Lander, USA |
Suprêmes délices | Boulevard Tirou, 255, B-6000 Charleroi, Belgium |
The Big Cheese | 89 Jefferson Way Suite 2, 97201 Portland, USA |
The Cracker Box | 55 Grizzly Peak Rd., 59801 Butte, USA |
Toms Spezialitäten | Luisenstr. 48, 44087 Münster, Germany |
Tortuga Restaurante | Avda. Azteca 123, 05033 México D.F., Mexico |
Tradição Hipermercados | Av. Inês de Castro, 414, 05634-030 São Paulo, Brazil |
Trail’s Head Gourmet Provisioners | 722 DaVinci Blvd., 98034 Kirkland, USA |
Vaffeljernet | Smagsløget 45, 8200 Århus, Denmark |
Victuailles en stock | 2, rue du Commerce, 69004 Lyon, France |
Vins et alcools Chevalier | 59 rue de l’Abbaye, 51100 Reims, France |
Die Wandernde Kuh | Adenauerallee 900, 70563 Stuttgart, Germany |
Wartian Herkku | Torikatu 38, 90110 Oulu, Finland |
Wellington Importadora | Rua do Mercado, 12, 08737-363 Resende, Brazil |
White Clover Markets | 305 – 14th Ave. S. Suite 3B, 98128 Seattle, USA |
Wilman Kala | Keskuskatu 45, 21240 Helsinki, Finland |
Wolski | ul. Filtrowa 68, 01-012 Walla, Poland |
테이블 별칭
CustomerID=4(Around the Horn)인 고객의 모든 주문을 선택하고 “고객”및 “주문”테이블을 사용하고 각각 “c”및 “o”의 테이블 별칭을 지정한다.
SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders AS o WHERE c.CustomerName='Around the Horn' AND c.CustomerID=o.CustomerID;
별칭 지정 없이 위와 동일한 SQL문
SELECT Orders.OrderID, Orders.OrderDate, Customers.CustomerName FROM Customers, Orders WHERE Customers.CustomerName='Around the Horn' AND Customers.CustomerID=Orders.CustomerID;
기본 예시
OrderID | OrderDate | CustomerName |
---|---|---|
10355 | 1996-11-15 | Around the Horn |
10383 | 1996-12-16 | Around the Horn |
참고
W3C School - SQL ALIAS Operator
W3C School - SQL Tutorial