25:
148:. Assigning an alias does not actually rename the column or table. This is often useful when either tables or their columns have very long or complex names. An alias name could be anything, but usually it is kept short. For example, it might be common to use a table alias such as "pi" for a table named "price_information".
421:
would produce the same result set as before. In this syntax it is permissible to omit aliases for some column names. In the example, an alias was provided for
DepartmentId, but omitted for DepartmentName. Columns with unspecified aliases will be left unaliased. This syntax is often used with
422:
expressions that do not produce useful table and column names, such as VALUES and UNNEST. As an example, one may conveniently test the above SQL statements without creating an actual
Departments table by using expressions such as
133:. Aliases provide users with the ability to reduce the amount of code required for a query, and to make queries simpler to understand. In addition, aliasing is required when doing self joins (i.e. joining a table with itself.)
169:. Note that the AS keyword is completely optional and is usually kept for readability purposes. Here is some sample data that the queries below will be referencing:
334:, the data shown above would be returned, with the only exception being "DepartmentID" would show up as "Id", and "DepartmentName" would show up as "Name".
144:, according to the SQL standard. A programmer can use an alias to temporarily assign another name to a table or column for the duration of the current
881:
876:
646:
641:
341:, it is permissible to omit the table name or table alias from the column name in the SELECT statement. Example as follows:
89:
61:
108:
547:
68:
381:
Some systems, such as
Postgres and Presto, support specifying column aliases together with table aliases. E.g.
46:
613:
75:
42:
57:
35:
789:
817:
250:
We can also write the same query like this (Note that the AS clause is omitted this time):
570:
8:
860:
582:
696:
82:
606:
137:
558:
810:
740:
931:
855:
796:
937:
906:
824:
803:
754:
747:
726:
719:
599:
145:
831:
768:
838:
775:
761:
733:
712:
338:
331:
337:
Also, if only one table is being selected and the query is not using
24:
782:
686:
681:
676:
671:
666:
661:
656:
916:
911:
901:
896:
891:
886:
651:
636:
130:
548:
538:
ANSI Standard SQL โ Foundation
Document โ Date: 2010-10-14
622:
126:
912:
SQL Routines and Types for the Java
Programming Language
571:
https://prestodb.io/docs/0.248/sql/values.html#examples
591:
583:
https://prestodb.io/docs/0.248/sql/select.html#unnest
49:. Unsourced material may be challenged and removed.
929:
131:relational database management systems (RDBMSs)
559:https://prestodb.io/docs/0.248/sql/select.html
607:
614:
600:
109:Learn how and when to remove this message
129:that is supported by most, if not all,
930:
595:
47:adding citations to reliable sources
18:
585:SELECT โ Presto 0.248 Documentation
573:VALUES โ Presto 0.248 Documentation
561:SELECT โ Presto 0.248 Documentation
13:
907:Information and Definition Schemas
151:The general syntax of an alias is
14:
949:
136:In SQL, you can alias tables and
23:
34:needs additional citations for
576:
564:
552:
541:
532:
1:
525:
140:. A table alias is called a
7:
897:Management of External Data
278:A column alias is similar:
10:
954:
917:XML-Related Specifications
892:Persistent Stored Modules
869:
848:
695:
629:
152:
902:Object Language Bindings
424:
383:
343:
280:
252:
221:
621:
219:Using a table alias:
887:Call-Level Interface
43:improve this article
861:Relational database
174:
172:
925:
924:
870:ISO/IEC SQL parts
217:
216:
173:Department Table
119:
118:
111:
93:
945:
841:
834:
827:
820:
813:
806:
799:
792:
785:
778:
771:
764:
757:
750:
743:
736:
729:
722:
715:
708:
616:
609:
602:
593:
592:
586:
580:
574:
568:
562:
556:
550:
545:
539:
536:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
491:
488:
485:
482:
479:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
417:
414:
411:
408:
405:
402:
399:
396:
393:
390:
387:
377:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
330:In the returned
326:
323:
320:
317:
314:
311:
308:
305:
302:
299:
296:
293:
290:
287:
284:
274:
271:
268:
265:
262:
259:
256:
246:
243:
240:
237:
234:
231:
228:
225:
175:
171:
168:
167:
164:
161:
158:
155:
142:correlation name
125:is a feature of
114:
107:
103:
100:
94:
92:
58:"Alias" SQL
51:
27:
19:
953:
952:
948:
947:
946:
944:
943:
942:
928:
927:
926:
921:
865:
844:
837:
830:
823:
816:
809:
802:
795:
788:
781:
774:
767:
760:
753:
746:
739:
732:
725:
718:
711:
704:
691:
625:
620:
590:
589:
581:
577:
569:
565:
557:
553:
546:
542:
537:
533:
528:
523:
522:
519:
516:
513:
510:
507:
504:
501:
498:
495:
492:
489:
486:
483:
480:
477:
474:
471:
468:
465:
462:
459:
456:
453:
450:
447:
444:
441:
438:
435:
432:
429:
426:
419:
418:
415:
412:
409:
406:
403:
400:
397:
394:
391:
388:
385:
379:
378:
375:
372:
369:
366:
363:
360:
357:
354:
351:
348:
345:
328:
327:
324:
321:
318:
315:
312:
309:
306:
303:
300:
297:
294:
291:
288:
285:
282:
276:
275:
272:
269:
266:
263:
260:
257:
254:
248:
247:
244:
241:
238:
235:
232:
229:
226:
223:
181:DepartmentName
165:
162:
159:
156:
153:
115:
104:
98:
95:
52:
50:
40:
28:
17:
12:
11:
5:
951:
941:
940:
923:
922:
920:
919:
914:
909:
904:
899:
894:
889:
884:
879:
873:
871:
867:
866:
864:
863:
858:
852:
850:
846:
845:
843:
842:
835:
828:
821:
814:
807:
800:
793:
786:
779:
772:
765:
758:
751:
744:
737:
730:
723:
716:
709:
701:
699:
693:
692:
690:
689:
684:
679:
674:
669:
664:
659:
654:
649:
644:
639:
633:
631:
627:
626:
619:
618:
611:
604:
596:
588:
587:
575:
563:
551:
540:
530:
529:
527:
524:
502:DepartmentName
442:DepartmentName
425:
384:
361:DepartmentName
344:
310:DepartmentName
281:
264:DepartmentName
253:
233:DepartmentName
222:
215:
214:
211:
207:
206:
203:
199:
198:
195:
191:
190:
187:
183:
182:
179:
117:
116:
31:
29:
22:
16:Feature of SQL
15:
9:
6:
4:
3:
2:
950:
939:
936:
935:
933:
918:
915:
913:
910:
908:
905:
903:
900:
898:
895:
893:
890:
888:
885:
883:
880:
878:
875:
874:
872:
868:
862:
859:
857:
854:
853:
851:
847:
840:
836:
833:
829:
826:
822:
819:
815:
812:
808:
805:
801:
798:
794:
791:
787:
784:
780:
777:
773:
770:
766:
763:
759:
756:
752:
749:
745:
742:
738:
735:
731:
728:
724:
721:
717:
714:
710:
707:
703:
702:
700:
698:
694:
688:
685:
683:
680:
678:
675:
673:
670:
668:
665:
663:
660:
658:
655:
653:
650:
648:
645:
643:
640:
638:
635:
634:
632:
628:
624:
617:
612:
610:
605:
603:
598:
597:
594:
584:
579:
572:
567:
560:
555:
549:
544:
535:
531:
423:
382:
342:
340:
335:
333:
279:
251:
220:
212:
209:
208:
204:
201:
200:
196:
193:
192:
188:
185:
184:
180:
177:
176:
170:
149:
147:
143:
139:
134:
132:
128:
124:
113:
110:
102:
91:
88:
84:
81:
77:
74:
70:
67:
63:
60: โ
59:
55:
54:Find sources:
48:
44:
38:
37:
32:This article
30:
26:
21:
20:
705:
578:
566:
554:
543:
534:
490:DepartmentId
481:'IT'
466:'HR'
436:DepartmentId
420:
380:
349:DepartmentId
336:
329:
292:DepartmentId
277:
249:
218:
197:Engineering
178:DepartmentID
150:
146:SELECT query
141:
135:
122:
120:
105:
99:October 2013
96:
86:
79:
72:
65:
53:
41:Please help
36:verification
33:
339:table joins
332:result sets
882:Foundation
856:Edgar Codd
526:References
514:Department
430:Department
401:Department
373:Department
322:Department
270:Department
239:Department
213:Marketing
166:alias_name
163:table_name
69:newspapers
877:Framework
205:Clerical
932:Category
811:Truncate
783:Order by
741:Group by
697:Keywords
687:SQL:2023
682:SQL:2016
677:SQL:2011
672:SQL:2008
667:SQL:2006
662:SQL:2003
657:SQL:1999
630:Versions
849:Related
797:Prepare
138:columns
83:scholar
825:Update
804:Select
755:Insert
748:Having
727:Delete
720:Create
652:SQL-92
647:SQL-89
642:SQL-86
637:SEQUEL
487:SELECT
454:VALUES
386:SELECT
346:SELECT
283:SELECT
255:SELECT
224:SELECT
189:Sales
154:SELECT
85:
78:
71:
64:
56:
832:Where
818:Union
769:Merge
123:alias
90:JSTOR
76:books
839:With
790:Over
776:Null
762:Join
734:From
713:Case
511:FROM
508:Name
427:WITH
398:FROM
370:FROM
367:Name
319:FROM
316:Name
267:FROM
236:FROM
160:FROM
62:news
938:SQL
623:SQL
127:SQL
121:An
45:by
934::
706:As
505:AS
496:Id
493:AS
484:))
469:),
448:AS
413:Id
404:AS
395:Id
364:AS
355:Id
352:AS
313:AS
298:Id
295:AS
242:AS
210:35
202:34
194:33
186:31
615:e
608:t
601:v
520:;
517:d
499:,
478:,
475:2
472:(
463:,
460:1
457:(
451:(
445:)
439:,
433:(
416:)
410:(
407:D
392:.
389:D
376:d
358:,
325:d
307:.
304:d
301:,
289:.
286:d
273:D
261:.
258:D
245:D
230:.
227:D
157:*
112:)
106:(
101:)
97:(
87:ยท
80:ยท
73:ยท
66:ยท
39:.
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.