SELECT CLAUSE

The SELECT clause is used to indicate which expressions to retrieve from the specified data source. Expressions can vary in complexity. Perhaps the least complex expressions are those involving pre-existing attributes. Pre-existing attributes are those attributes already captured within the data source. Other types of expressions include derived attributes, scalar values, and combinations of different types of expressions, among others. It can be difficult to understand the various types of expressions possible within the SELECT clause without concrete examples, so let’s walk through a few.

Before reading further, consider reviewing the Example Data section below to familiarize yourself with the data being used throughout the examples on this page. If you are already familiar with the data, then skip to the Pre-existing Attributes section

Example Data
The schemas, corresponding tables, and data used in the example problems can be found at livesql.oracle.com. To more easily follow the examples covered on this page, consider first reading the table descriptions below and reviewing each table’s contents. To review the data maintained in each table, click on the icon next to the table name. To hide the data, click the icon again.

hr.employees
Contains information related to each employee and a hierarchal employee-manager relationship. There is one row per employee.
employee_idfirst_namelast_nameemailphone_numberhire_datejob_idsalarycommission_pctmanager_iddepartment_id
100StevenKingSKING515.123.456717-Jun-03AD_PRES2400090
101NeenaKochharNKOCHHAR515.123.456821-Sep-05AD_VP1700010090
102LexDe HaanLDEHAAN515.123.456913-Jan-01AD_VP1700010090
103AlexanderHunoldAHUNOLD590.423.45673-Jan-06IT_PROG900010260
104BruceErnstBERNST590.423.456821-May-07IT_PROG600010360
105DavidAustinDAUSTIN590.423.456925-Jun-05IT_PROG480010360
106ValliPataballaVPATABAL590.423.45605-Feb-06IT_PROG480010360
107DianaLorentzDLORENTZ590.423.55677-Feb-07IT_PROG420010360
108NancyGreenbergNGREENBE515.124.456917-Aug-02FI_MGR12008101100
109DanielFavietDFAVIET515.124.416916-Aug-02FI_ACCOUNT9000108100
110JohnChenJCHEN515.124.426928-Sep-05FI_ACCOUNT8200108100
111IsmaelSciarraISCIARRA515.124.436930-Sep-05FI_ACCOUNT7700108100
112Jose ManuelUrmanJMURMAN515.124.44697-Mar-06FI_ACCOUNT7800108100
113LuisPoppLPOPP515.124.45677-Dec-07FI_ACCOUNT6900108100
114DenRaphaelyDRAPHEAL515.127.45617-Dec-02PU_MAN1100010030
115AlexanderKhooAKHOO515.127.456218-May-03PU_CLERK310011430
116ShelliBaidaSBAIDA515.127.456324-Dec-05PU_CLERK290011430
117SigalTobiasSTOBIAS515.127.456424-Jul-05PU_CLERK280011430
118GuyHimuroGHIMURO515.127.456515-Nov-06PU_CLERK260011430
119KarenColmenaresKCOLMENA515.127.456610-Aug-07PU_CLERK250011430
120MatthewWeissMWEISS650.123.123418-Jul-04ST_MAN800010050
121AdamFrippAFRIPP650.123.223410-Apr-05ST_MAN820010050
122PayamKauflingPKAUFLIN650.123.32341-May-03ST_MAN790010050
123ShantaVollmanSVOLLMAN650.123.423410-Oct-05ST_MAN650010050
124KevinMourgosKMOURGOS650.123.523416-Nov-07ST_MAN580010050
125JuliaNayerJNAYER650.124.121416-Jul-05ST_CLERK320012050
126IreneMikkilineniIMIKKILI650.124.122428-Sep-06ST_CLERK270012050
127JamesLandryJLANDRY650.124.133414-Jan-07ST_CLERK240012050
128StevenMarkleSMARKLE650.124.14348-Mar-08ST_CLERK220012050
129LauraBissotLBISSOT650.124.523420-Aug-05ST_CLERK330012150
130MozheAtkinsonMATKINSO650.124.623430-Oct-05ST_CLERK280012150
131JamesMarlowJAMRLOW650.124.723416-Feb-05ST_CLERK250012150
132TJOlsonTJOLSON650.124.823410-Apr-07ST_CLERK210012150
133JasonMallinJMALLIN650.127.193414-Jun-04ST_CLERK330012250
134MichaelRogersMROGERS650.127.183426-Aug-06ST_CLERK290012250
135KiGeeKGEE650.127.173412-Dec-07ST_CLERK240012250
136HazelPhiltankerHPHILTAN650.127.16346-Feb-08ST_CLERK220012250
137RenskeLadwigRLADWIG650.121.123414-Jul-03ST_CLERK360012350
138StephenStilesSSTILES650.121.203426-Oct-05ST_CLERK320012350
139JohnSeoJSEO650.121.201912-Feb-06ST_CLERK270012350
140JoshuaPatelJPATEL650.121.18346-Apr-06ST_CLERK250012350
141TrennaRajsTRAJS650.121.800917-Oct-03ST_CLERK350012450
142CurtisDaviesCDAVIES650.121.299429-Jan-05ST_CLERK310012450
143RandallMatosRMATOS650.121.287415-Mar-06ST_CLERK260012450
144PeterVargasPVARGAS650.121.20049-Jul-06ST_CLERK250012450
145JohnRussellJRUSSEL011.44.1344.4292681-Oct-04SA_MAN140000.410080
146KarenPartnersKPARTNER011.44.1344.4672685-Jan-05SA_MAN135000.310080
147AlbertoErrazurizAERRAZUR011.44.1344.42927810-Mar-05SA_MAN120000.310080
148GeraldCambraultGCAMBRAU011.44.1344.61926815-Oct-07SA_MAN110000.310080
149EleniZlotkeyEZLOTKEY011.44.1344.42901829-Jan-08SA_MAN105000.210080
150PeterTuckerPTUCKER011.44.1344.12926830-Jan-05SA_REP100000.314580
151DavidBernsteinDBERNSTE011.44.1344.34526824-Mar-05SA_REP95000.2514580
152PeterHallPHALL011.44.1344.47896820-Aug-05SA_REP90000.2514580
153ChristopherOlsenCOLSEN011.44.1344.49871830-Mar-06SA_REP80000.214580
154NanetteCambraultNCAMBRAU011.44.1344.9876689-Dec-06SA_REP75000.214580
155OliverTuvaultOTUVAULT011.44.1344.48650823-Nov-07SA_REP70000.1514580
156JanetteKingJKING011.44.1345.42926830-Jan-04SA_REP100000.3514680
157PatrickSullyPSULLY011.44.1345.9292684-Mar-04SA_REP95000.3514680
158AllanMcEwenAMCEWEN011.44.1345.8292681-Aug-04SA_REP90000.3514680
159LindseySmithLSMITH011.44.1345.72926810-Mar-05SA_REP80000.314680
160LouiseDoranLDORAN011.44.1345.62926815-Dec-05SA_REP75000.314680
161SarathSewallSSEWALL011.44.1345.5292683-Nov-06SA_REP70000.2514680
162ClaraVishneyCVISHNEY011.44.1346.12926811-Nov-05SA_REP105000.2514780
163DanielleGreeneDGREENE011.44.1346.22926819-Mar-07SA_REP95000.1514780
164MatteaMarvinsMMARVINS011.44.1346.32926824-Jan-08SA_REP72000.114780
165DavidLeeDLEE011.44.1346.52926823-Feb-08SA_REP68000.114780
166SundarAndeSANDE011.44.1346.62926824-Mar-08SA_REP64000.114780
167AmitBandaABANDA011.44.1346.72926821-Apr-08SA_REP62000.114780
168LisaOzerLOZER011.44.1343.92926811-Mar-05SA_REP115000.2514880
169HarrisonBloomHBLOOM011.44.1343.82926823-Mar-06SA_REP100000.214880
170TaylerFoxTFOX011.44.1343.72926824-Jan-06SA_REP96000.214880
171WilliamSmithWSMITH011.44.1343.62926823-Feb-07SA_REP74000.1514880
172ElizabethBatesEBATES011.44.1343.52926824-Mar-07SA_REP73000.1514880
173SunditaKumarSKUMAR011.44.1343.32926821-Apr-08SA_REP61000.114880
174EllenAbelEABEL011.44.1644.42926711-May-04SA_REP110000.314980
175AlyssaHuttonAHUTTON011.44.1644.42926619-Mar-05SA_REP88000.2514980
176JonathonTaylorJTAYLOR011.44.1644.42926524-Mar-06SA_REP86000.214980
177JackLivingstonJLIVINGS011.44.1644.42926423-Apr-06SA_REP84000.214980
178KimberelyGrantKGRANT011.44.1644.42926324-May-07SA_REP70000.15149
179CharlesJohnsonCJOHNSON011.44.1644.4292624-Jan-08SA_REP62000.114980
180WinstonTaylorWTAYLOR650.507.987624-Jan-06SH_CLERK320012050
181JeanFleaurJFLEAUR650.507.987723-Feb-06SH_CLERK310012050
182MarthaSullivanMSULLIVA650.507.987821-Jun-07SH_CLERK250012050
183GirardGeoniGGEONI650.507.98793-Feb-08SH_CLERK280012050
184NanditaSarchandNSARCHAN650.509.187627-Jan-04SH_CLERK420012150
185AlexisBullABULL650.509.287620-Feb-05SH_CLERK410012150
186JuliaDellingerJDELLING650.509.387624-Jun-06SH_CLERK340012150
187AnthonyCabrioACABRIO650.509.48767-Feb-07SH_CLERK300012150
188KellyChungKCHUNG650.505.187614-Jun-05SH_CLERK380012250
189JenniferDillyJDILLY650.505.287613-Aug-05SH_CLERK360012250
190TimothyGatesTGATES650.505.387611-Jul-06SH_CLERK290012250
191RandallPerkinsRPERKINS650.505.487619-Dec-07SH_CLERK250012250
192SarahBellSBELL650.501.18764-Feb-04SH_CLERK400012350
193BritneyEverettBEVERETT650.501.28763-Mar-05SH_CLERK390012350
194SamuelMcCainSMCCAIN650.501.38761-Jul-06SH_CLERK320012350
195VanceJonesVJONES650.501.487617-Mar-07SH_CLERK280012350
196AlanaWalshAWALSH650.507.981124-Apr-06SH_CLERK310012450
197KevinFeeneyKFEENEY650.507.982223-May-06SH_CLERK300012450
198DonaldOConnellDOCONNEL650.507.983321-Jun-07SH_CLERK260012450
199DouglasGrantDGRANT650.507.984413-Jan-08SH_CLERK260012450
200JenniferWhalenJWHALEN515.123.444417-Sep-03AD_ASST440010110
201MichaelHartsteinMHARTSTE515.123.555517-Feb-04MK_MAN1300010020
202PatFayPFAY603.123.666617-Aug-05MK_REP600020120
203SusanMavrisSMAVRIS515.123.77777-Jun-02HR_REP650010140
204HermannBaerHBAER515.123.88887-Jun-02PR_REP1000010170
205ShelleyHigginsSHIGGINS515.123.80807-Jun-02AC_MGR12008101110
206WilliamGietzWGIETZ515.123.81817-Jun-02AC_ACCOUNT8300205110
hr.jobs
Contains information related to each job. It’s possible for a job to exist without being assigned to any employee. There is one row per job.
job_idjob_titlemin_salarymax_salary
AD_PRESPresident2008040000
AD_VPAdministration Vice President1500030000
AD_ASSTAdministration Assistant30006000
FI_MGRFinance Manager820016000
FI_ACCOUNTAccountant42009000
AC_MGRAccounting Manager820016000
AC_ACCOUNTPublic Accountant42009000
SA_MANSales Manager1000020080
SA_REPSales Representative600012008
PU_MANPurchasing Manager800015000
PU_CLERKPurchasing Clerk25005500
ST_MANStock Manager55008500
ST_CLERKStock Clerk20085000
SH_CLERKShipping Clerk25005500
IT_PROGProgrammer400010000
MK_MANMarketing Manager900015000
MK_REPMarketing Representative40009000
HR_REPHuman Resources Representative40009000
PR_REPPublic Relations Representative450010500

Pre-existing Attributes
For the first example, let’s consider a scenario where the task is to generate a report containing the ID, first name, last name, and hire date of each employee. Based on the employees table above, each of these attributes are part of the table’s definition and are already being captured. As a result, we simply need to list those attributes within the SELECT clause and specify the data source or object containing the attributes of interest using the FROM clause. For the examples on this page, it is sufficient to simply know the FROM clause follows the expression list and is used to specify the data source. The code required to fulfill the task and the corresponding output can be found below.

SELECT
    hr.employees.employee_id,
    hr.employees.first_name,
    hr.employees.last_name,
    hr.employees.hire_date
FROM
    hr.employees;
employee_idfirst_namelast_namehire_date
100StevenKing17-JUN-03
101NeenaKochhar21-SEP-05
102LexDe Haan13-JAN-01
103AlexanderHunold03-JAN-06
104BruceErnst21-MAY-07
105DavidAustin25-JUN-05
106ValliPataballa05-FEB-06
107DianaLorentz07-FEB-07
108NancyGreenberg17-AUG-02
109DanielFaviet16-AUG-02
110JohnChen28-SEP-05
111IsmaelSciarra30-SEP-05
112Jose ManuelUrman07-MAR-06
113LuisPopp07-DEC-07
114DenRaphaely07-DEC-02
115AlexanderKhoo18-MAY-03
116ShelliBaida24-DEC-05
117SigalTobias24-JUL-05
118GuyHimuro15-NOV-06
119KarenColmenares10-AUG-07
120MatthewWeiss18-JUL-04
121AdamFripp10-APR-05
122PayamKaufling01-MAY-03
123ShantaVollman10-OCT-05
124KevinMourgos16-NOV-07
125JuliaNayer16-JUL-05
126IreneMikkilineni28-SEP-06
127JamesLandry14-JAN-07
128StevenMarkle08-MAR-08
129LauraBissot20-AUG-05
130MozheAtkinson30-OCT-05
131JamesMarlow16-FEB-05
132TJOlson10-APR-07
133JasonMallin14-JUN-04
134MichaelRogers26-AUG-06
135KiGee12-DEC-07
136HazelPhiltanker06-FEB-08
137RenskeLadwig14-JUL-03
138StephenStiles26-OCT-05
139JohnSeo12-FEB-06
140JoshuaPatel06-APR-06
141TrennaRajs17-OCT-03
142CurtisDavies29-JAN-05
143RandallMatos15-MAR-06
144PeterVargas09-JUL-06
145JohnRussell01-OCT-04
146KarenPartners05-JAN-05
147AlbertoErrazuriz10-MAR-05
148GeraldCambrault15-OCT-07
149EleniZlotkey29-JAN-08
150PeterTucker30-JAN-05
151DavidBernstein24-MAR-05
152PeterHall20-AUG-05
153ChristopherOlsen30-MAR-06
154NanetteCambrault09-DEC-06
155OliverTuvault23-NOV-07
156JanetteKing30-JAN-04
157PatrickSully04-MAR-04
158AllanMcEwen01-AUG-04
159LindseySmith10-MAR-05
160LouiseDoran15-DEC-05
161SarathSewall03-NOV-06
162ClaraVishney11-NOV-05
163DanielleGreene19-MAR-07
164MatteaMarvins24-JAN-08
165DavidLee23-FEB-08
166SundarAnde24-MAR-08
167AmitBanda21-APR-08
168LisaOzer11-MAR-05
169HarrisonBloom23-MAR-06
170TaylerFox24-JAN-06
171WilliamSmith23-FEB-07
172ElizabethBates24-MAR-07
173SunditaKumar21-APR-08
174EllenAbel11-MAY-04
175AlyssaHutton19-MAR-05
176JonathonTaylor24-MAR-06
177JackLivingston23-APR-06
178KimberelyGrant24-MAY-07
179CharlesJohnson04-JAN-08
180WinstonTaylor24-JAN-06
181JeanFleaur23-FEB-06
182MarthaSullivan21-JUN-07
183GirardGeoni03-FEB-08
184NanditaSarchand27-JAN-04
185AlexisBull20-FEB-05
186JuliaDellinger24-JUN-06
187AnthonyCabrio07-FEB-07
188KellyChung14-JUN-05
189JenniferDilly13-AUG-05
190TimothyGates11-JUL-06
191RandallPerkins19-DEC-07
192SarahBell04-FEB-04
193BritneyEverett03-MAR-05
194SamuelMcCain01-JUL-06
195VanceJones17-MAR-07
196AlanaWalsh24-APR-06
197KevinFeeney23-MAY-06
198DonaldOConnell21-JUN-07
199DouglasGrant13-JAN-08
200JenniferWhalen17-SEP-03
201MichaelHartstein17-FEB-04
202PatFay17-AUG-05
203SusanMavris07-JUN-02
204HermannBaer07-JUN-02
205ShelleyHiggins07-JUN-02
206WilliamGietz07-JUN-02

Notice the commas present in the code above. When there is more than one expression, it is required to separate expressions with commas, leaving off the trailing comma. In the beginning of your SQL learning journey, it may be helpful to remember each SELECT clause requires one less comma than the number of expressions specified (i.e., n-1).

Derived Attributes
Derived attributes bridge the gap between the attributes stored in the data source and the attributes we need at any given time. Suppose, we are tasked with generating a report for people managers reminding them of important dates and milestones for each employee, such as the following:

– Benefits eligibility date (i.e., 30 days following the hire date)
– Ninety day review (i.e., 90 days following the hire date)
– One-year anniversary
– Five-year anniversary

These data points are not being captured, so we’ll need to derive them at run-time. To do so, we’ll take advantage of Oracle’s built-in function, ADD_MONTHS, and straightforward means to perform date arithmetic. The code required to fulfill the task and the corresponding output can be found below. To learn more about Oracle’s built-in datetime functions and date arithmetic through real-world examples, see my datetime functions page.

SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.hire_date + 30 AS benefits_eligible_date,
    hr.employees.hire_date + 90 AS ninety_day_review,
    ADD_MONTHS(hr.employees.hire_date, 12) AS one_year_anniversary,
    ADD_MONTHS(hr.employees.hire_date, 60) AS five_year_anniversay
FROM
    hr.employees;
employee_idhire_datebenefits_eligible_dateninety_day_reviewone_year_anniversaryfive_year_anniversary
10017-JUN-0317-JUL-0315-SEP-0317-JUN-0417-JUN-08
10121-SEP-0521-OCT-0520-DEC-0521-SEP-0621-SEP-10
10213-JAN-0112-FEB-0113-APR-0113-JAN-0213-JAN-06
10303-JAN-0602-FEB-0603-APR-0603-JAN-0703-JAN-11
10421-MAY-0720-JUN-0719-AUG-0721-MAY-0821-MAY-12
10525-JUN-0525-JUL-0523-SEP-0525-JUN-0625-JUN-10
10605-FEB-0607-MAR-0606-MAY-0605-FEB-0705-FEB-11
10707-FEB-0709-MAR-0708-MAY-0707-FEB-0807-FEB-12
10817-AUG-0216-SEP-0215-NOV-0217-AUG-0317-AUG-07
10916-AUG-0215-SEP-0214-NOV-0216-AUG-0316-AUG-07
11028-SEP-0528-OCT-0527-DEC-0528-SEP-0628-SEP-10
11130-SEP-0530-OCT-0529-DEC-0530-SEP-0630-SEP-10
11207-MAR-0606-APR-0605-JUN-0607-MAR-0707-MAR-11
11307-DEC-0706-JAN-0806-MAR-0807-DEC-0807-DEC-12
11407-DEC-0206-JAN-0307-MAR-0307-DEC-0307-DEC-07
11518-MAY-0317-JUN-0316-AUG-0318-MAY-0418-MAY-08
11624-DEC-0523-JAN-0624-MAR-0624-DEC-0624-DEC-10
11724-JUL-0523-AUG-0522-OCT-0524-JUL-0624-JUL-10
11815-NOV-0615-DEC-0613-FEB-0715-NOV-0715-NOV-11
11910-AUG-0709-SEP-0708-NOV-0710-AUG-0810-AUG-12
12018-JUL-0417-AUG-0416-OCT-0418-JUL-0518-JUL-09
12110-APR-0510-MAY-0509-JUL-0510-APR-0610-APR-10
12201-MAY-0331-MAY-0330-JUL-0301-MAY-0401-MAY-08
12310-OCT-0509-NOV-0508-JAN-0610-OCT-0610-OCT-10
12416-NOV-0716-DEC-0714-FEB-0816-NOV-0816-NOV-12
12516-JUL-0515-AUG-0514-OCT-0516-JUL-0616-JUL-10
12628-SEP-0628-OCT-0627-DEC-0628-SEP-0728-SEP-11
12714-JAN-0713-FEB-0714-APR-0714-JAN-0814-JAN-12
12808-MAR-0807-APR-0806-JUN-0808-MAR-0908-MAR-13
12920-AUG-0519-SEP-0518-NOV-0520-AUG-0620-AUG-10
13030-OCT-0529-NOV-0528-JAN-0630-OCT-0630-OCT-10
13116-FEB-0518-MAR-0517-MAY-0516-FEB-0616-FEB-10
13210-APR-0710-MAY-0709-JUL-0710-APR-0810-APR-12
13314-JUN-0414-JUL-0412-SEP-0414-JUN-0514-JUN-09
13426-AUG-0625-SEP-0624-NOV-0626-AUG-0726-AUG-11
13512-DEC-0711-JAN-0811-MAR-0812-DEC-0812-DEC-12
13606-FEB-0807-MAR-0806-MAY-0806-FEB-0906-FEB-13
13714-JUL-0313-AUG-0312-OCT-0314-JUL-0414-JUL-08
13826-OCT-0525-NOV-0524-JAN-0626-OCT-0626-OCT-10
13912-FEB-0614-MAR-0613-MAY-0612-FEB-0712-FEB-11
14006-APR-0606-MAY-0605-JUL-0606-APR-0706-APR-11
14117-OCT-0316-NOV-0315-JAN-0417-OCT-0417-OCT-08
14229-JAN-0528-FEB-0529-APR-0529-JAN-0629-JAN-10
14315-MAR-0614-APR-0613-JUN-0615-MAR-0715-MAR-11
14409-JUL-0608-AUG-0607-OCT-0609-JUL-0709-JUL-11
14501-OCT-0431-OCT-0430-DEC-0401-OCT-0501-OCT-09
14605-JAN-0504-FEB-0505-APR-0505-JAN-0605-JAN-10
14710-MAR-0509-APR-0508-JUN-0510-MAR-0610-MAR-10
14815-OCT-0714-NOV-0713-JAN-0815-OCT-0815-OCT-12
14929-JAN-0828-FEB-0828-APR-0829-JAN-0929-JAN-13
15030-JAN-0501-MAR-0530-APR-0530-JAN-0630-JAN-10
15124-MAR-0523-APR-0522-JUN-0524-MAR-0624-MAR-10
15220-AUG-0519-SEP-0518-NOV-0520-AUG-0620-AUG-10
15330-MAR-0629-APR-0628-JUN-0630-MAR-0730-MAR-11
15409-DEC-0608-JAN-0709-MAR-0709-DEC-0709-DEC-11
15523-NOV-0723-DEC-0721-FEB-0823-NOV-0823-NOV-12
15630-JAN-0429-FEB-0429-APR-0430-JAN-0530-JAN-09
15704-MAR-0403-APR-0402-JUN-0404-MAR-0504-MAR-09
15801-AUG-0431-AUG-0430-OCT-0401-AUG-0501-AUG-09
15910-MAR-0509-APR-0508-JUN-0510-MAR-0610-MAR-10
16015-DEC-0514-JAN-0615-MAR-0615-DEC-0615-DEC-10
16103-NOV-0603-DEC-0601-FEB-0703-NOV-0703-NOV-11
16211-NOV-0511-DEC-0509-FEB-0611-NOV-0611-NOV-10
16319-MAR-0718-APR-0717-JUN-0719-MAR-0819-MAR-12
16424-JAN-0823-FEB-0823-APR-0824-JAN-0924-JAN-13
16523-FEB-0824-MAR-0823-MAY-0823-FEB-0923-FEB-13
16624-MAR-0823-APR-0822-JUN-0824-MAR-0924-MAR-13
16721-APR-0821-MAY-0820-JUL-0821-APR-0921-APR-13
16811-MAR-0510-APR-0509-JUN-0511-MAR-0611-MAR-10
16923-MAR-0622-APR-0621-JUN-0623-MAR-0723-MAR-11
17024-JAN-0623-FEB-0624-APR-0624-JAN-0724-JAN-11
17123-FEB-0725-MAR-0724-MAY-0723-FEB-0823-FEB-12
17224-MAR-0723-APR-0722-JUN-0724-MAR-0824-MAR-12
17321-APR-0821-MAY-0820-JUL-0821-APR-0921-APR-13
17411-MAY-0410-JUN-0409-AUG-0411-MAY-0511-MAY-09
17519-MAR-0518-APR-0517-JUN-0519-MAR-0619-MAR-10
17624-MAR-0623-APR-0622-JUN-0624-MAR-0724-MAR-11
17723-APR-0623-MAY-0622-JUL-0623-APR-0723-APR-11
17824-MAY-0723-JUN-0722-AUG-0724-MAY-0824-MAY-12
17904-JAN-0803-FEB-0803-APR-0804-JAN-0904-JAN-13
18024-JAN-0623-FEB-0624-APR-0624-JAN-0724-JAN-11
18123-FEB-0625-MAR-0624-MAY-0623-FEB-0723-FEB-11
18221-JUN-0721-JUL-0719-SEP-0721-JUN-0821-JUN-12
18303-FEB-0804-MAR-0803-MAY-0803-FEB-0903-FEB-13
18427-JAN-0426-FEB-0426-APR-0427-JAN-0527-JAN-09
18520-FEB-0522-MAR-0521-MAY-0520-FEB-0620-FEB-10
18624-JUN-0624-JUL-0622-SEP-0624-JUN-0724-JUN-11
18707-FEB-0709-MAR-0708-MAY-0707-FEB-0807-FEB-12
18814-JUN-0514-JUL-0512-SEP-0514-JUN-0614-JUN-10
18913-AUG-0512-SEP-0511-NOV-0513-AUG-0613-AUG-10
19011-JUL-0610-AUG-0609-OCT-0611-JUL-0711-JUL-11
19119-DEC-0718-JAN-0818-MAR-0819-DEC-0819-DEC-12
19204-FEB-0405-MAR-0404-MAY-0404-FEB-0504-FEB-09
19303-MAR-0502-APR-0501-JUN-0503-MAR-0603-MAR-10
19401-JUL-0631-JUL-0629-SEP-0601-JUL-0701-JUL-11
19517-MAR-0716-APR-0715-JUN-0717-MAR-0817-MAR-12
19624-APR-0624-MAY-0623-JUL-0624-APR-0724-APR-11
19723-MAY-0622-JUN-0621-AUG-0623-MAY-0723-MAY-11
19821-JUN-0721-JUL-0719-SEP-0721-JUN-0821-JUN-12
19913-JAN-0812-FEB-0812-APR-0813-JAN-0913-JAN-13
20017-SEP-0317-OCT-0316-DEC-0317-SEP-0417-SEP-08
20117-FEB-0418-MAR-0417-MAY-0417-FEB-0517-FEB-09
20217-AUG-0516-SEP-0515-NOV-0517-AUG-0617-AUG-10
20307-JUN-0207-JUL-0205-SEP-0207-JUN-0307-JUN-07
20407-JUN-0207-JUL-0205-SEP-0207-JUN-0307-JUN-07
20507-JUN-0207-JUL-0205-SEP-0207-JUN-0307-JUN-07
20607-JUN-0207-JUL-0205-SEP-0207-JUN-0307-JUN-07

Scalar Values
A task’s requirements may require you to incorporate scalar values (e.g., 1, 1.10, 100, etc.) into your solution. For example, suppose human resources would like you to generate a report displaying each employee’s salary. Additionally, they would like to see employees’ salaries with a three percent increase applied. To achieve this, simply multiply the pre-existing attribute, salary, by 1.03 using the ‘*’ symbol. For clarity, see the code and corresponding output below.

SELECT
    hr.employees.employee_id,
	hr.employees.salary,
	hr.employees.salary * 1.03 AS new_salary
FROM
	hr.employees;
employee_idsalarynew_salary
1002400024720
1011700017510
1021700017510
10390009270
10460006180
10548004944
10648004944
10742004326
1081200812368.24
10990009270
11082008446
11177007931
11278008034
11369007107
1141100011330
11531003193
11629002987
11728002884
11826002678
11925002575
12080008240
12182008446
12279008137
12365006695
12458005974
12532003296
12627002781
12724002472
12822002266
12933003399
13028002884
13125002575
13221002163
13333003399
13429002987
13524002472
13622002266
13736003708
13832003296
13927002781
14025002575
14135003605
14231003193
14326002678
14425002575
1451400014420
1461350013905
1471200012360
1481100011330
1491050010815
1501000010300
15195009785
15290009270
15380008240
15475007725
15570007210
1561000010300
15795009785
15890009270
15980008240
16075007725
16170007210
1621050010815
16395009785
16472007416
16568007004
16664006592
16762006386
1681150011845
1691000010300
17096009888
17174007622
17273007519
17361006283
1741100011330
17588009064
17686008858
17784008652
17870007210
17962006386
18032003296
18131003193
18225002575
18328002884
18442004326
18541004223
18634003502
18730003090
18838003914
18936003708
19029002987
19125002575
19240004120
19339004017
19432003296
19528002884
19631003193
19730003090
19826002678
19926002678
20044004532
2011300013390
20260006180
20365006695
2041000010300
2051200812368.24
20683008549

Most mathematical operations or equations can be easily incorporated into your coding solutions using traditional operators (e.g., +, -, *, /). When performing division, ensure the output values do not deviate from the expected values. The handling of integer division varies among relational database management systems and “banker’s” rounding may occur.

Attribute Aliases
In the previous two examples, attributes were derived based on a combination of pre-existing attributes, scalar values, and the output of built-in functions. Using the AS keyword, a name for each derived attribute was provided. Use the AS keyword to provide meaningful names to derived attributes. If a name is not provided in the query, the attribute name will reflect its derivation. For example, the new_salary attribute above would read as “salary*1.03” in the absence of the AS keyword and a user-specified name.

Common Errors
One of the most common errors observe new SQL users make is including a trailing comma in the SELECT clause. When a comma follows the final expression specified in the SELECT clause, the relational database management system (RDBMS) will return an error. For Oracle, that error is ORA-00936: missing expression. If you remember the purpose of the commas in the SELECT clause is to separate the expressions listed, then this error message is rather helpful and makes sense. The RDBMS is expecting an expression to follow the comma!

Another error I frequently see new SQL users make is not including the necessary number of commas in the SELECT clause when more than one expression is specified. For example, suppose a query contains four expressions in the SELECT clause and the comma required after expression two is missing. When that query is executed, Oracle database will return the error, ORA-00923: FROM keyword not found where expected.

SQL veterans and new users alike make errors; the difference is experience in troubleshooting. Understanding a handful of common errors will allow you to jump to specific sections of your coding solution to resolve the errors quickly instead of requiring a more lengthy, top-down review.

Knowledge Check
If you’d like to confirm your understanding on the SELECT clause and other fundamental concepts, consider solving a handful of my practice problems here.