Fundamentals of Data Analysis (Access)
Fundamentals of Data Analysis (Access)
Data Analysis
Introduction After creating a table and populating it with records, you may want to see what you can do with data stored in it. One of the most commonly performed operations by the users of a database is to look for data or to isolate data that responds to a particular criterion. Looking for data that is conform to a criterion is referred to as querying. The result of retrie ing data based on a criterion is called a query.
database developer, you perform queries by passing instructions to the database engine. This is done using some special
As a reser ed words.
Server, data analysis can be performed using "#L "er er Management "tudio or in a query window.
In !icrosoft "#L The $ata in the Table %indow To isually analy&e data, in the Ob'ect ()plorer, you can right*click a table and click Open Table. +ere is an e)ample,
Once the table is opened, on the main menu, you can click #uery $esigner. Alternati ely, you can right*click anywhere on the table. In both cases .. On the menu that appears, position the mouse on /. Once again, open the 0ane menu and click 1riteria 2. Again, open the 0ane menu and click
SQL,
Alternati ely, on the #uery $esigner toolbar, you can click the "how $iagram 0ane button "how 1riteria 0ane button , and the "how "#L 0ane button .
, the
.. $iagram, The top section is referred to as the $iagram window. It displays the table3s4 that contain3s4 the columns you want to query. (ach column displays a check bo) on its left and the name of the column on the right. The first item of the list has a name made of an asterisk and the 3All 1olumns4 e)pression. If the list of items is too long for the allocated rectangle to display, the table would be equipped with a ertical scroll bar. /. 1riteria, 5nder the table, the second section is called 1riteria. It displays a list of columns used to isually build the . 2. "#L, The third section from top, called "#L, displays the "#L statement that results from selections in the $iagram or the 1riteria sections 6. 7esults, The bottom section, called 7esults, displays the result produced by the "#L statement when it is e)ecuted If you don8t want a particular section or you want to hide some sections, you can right*click anywhere in the table, position the mouse on 0ane and click the name of the section. To hide any section, you can right*click anywhere in the window, position the mouse on "how 0anes and click one of the selections,
SQL statement
%hen a section is displaying, its menu option is surrounded. 1olumn "election A "#L statement is primarily built by selecting one or more columns whose data you want to iew. To select a column, in the $iagram section of the Table window, you can click the check bo) on the left side of the name,
After clicking the check bo) of a column, it becomes selected in the 1riteria section also and its name appears in the "#L section. Another technique used to select a column consists of clicking a bo) under the 1olumn of the 1riteria section. This would re eal that it is a combo bo). 9ou can then click the arrow of the combo bo) to display the list and select a column from that list,
header
In the 1riteria section, if you click a combo bo) that already contains a column but select another, the pre ious one would be replaced by the new one. Also, after selecting a column in the 1riteria section, its check bo) becomes selected in the $iagram section and its name gets added to the "#L ersion. If you know the name of a column that you want to add, which you can see in the $iagram section, you can directly enter it in the "#L statement. Any of the abo e three techniques allows you to select one or more columns to build the desired "#L statement. "#L "tatement ()ecution After creating a "#L statement, you can iew its result, which you can get by e)ecuting the statement. To do this, you can right*click anywhere in the Table window and click ()ecute "#L. Alternati ely, on the toolbar, you can click the ()ecute "#L button .
After e)ecuting the statement, the bottom section gets filled with data from only the selected column3s4 of the table. +ere is an e)ample,
Transact*"#L and $ata Analysis Introduction $ata Analysis is actually performed using "#L code that contains one or more criteria. To prepare for data analysis, you ha e arious options,
If you ha en8t yet decided what table holds the data you want to analy&e, in the Ob'ect ()plorer, you can right*click a database and click :ew #uery. Then, in the query window, enter the necessary "#L statement If you know the table that holds the data you want to analy&e, in the Ob'ect ()plorer, right* click the table, position the mouse on "cript Table As, followed by SELECT To, and click :ew #uery (ditor %indow. A query window would be opened with sample "#L code
.. "tart
Microsoft SQL Server with the "#L Server Management "tudio and connect to the ser er
----IF ============================================= Author: FunctionX Database: RealEstate1 ============================================= EXISTS ( SELECT * FR ! s"s#$atabases %&ERE na'e = ()RealEstate1)
/. On the main menu, click File *; :ew *; #uery %ith 1urrent 1onnection 2. To prepare a database for our e)ercises, type the following,
DR + DATA,ASE RealEstate1 CREATE DATA,ASE RealEstate1. -- ============================================= -- Author: FunctionX -- Database: RealEstate1 -- Table: +ro/erties -- ============================================= 0SE RealEstate1. CREATE TA,LE +ro/erties ( +ro/ert"ID int i$entit"(111* ( T (0LL1 +ro/ert"(u'ber char(2*1 A$$ress 3archar(144*1 Cit" 3archar(54*1 State char(6*1 7I+Co$e 3archar(16*1 +ro/ert"T"/e 3archar(84*1 Con$ition 3archar(96*1 ,e$roo's s'allint1 ,athroo's :loat1 Finishe$,ase'ent bit1 In$oor-ara;e bit1 Stories s'allint1 <ear,uilt s'allint1 !ar=et>alue 'one" *. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()568??4)1 )1284 Lo'bar$o A3e)1 )Sil3er S/rin;)1 )!D)1 )64@48)1 )Sin;le Fa'il")1 )-oo$)1 81 6#51 91 11 91 1@@51 8@5??4#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue*
>AL0ES()2??928)1 )14915 (orth &acht R$)1 )Colle;e +ar=)1 )!D)1 )64A8A)1 )Sin;le Fa'il")1 )EBcellent)1 81 9#51 91 11 61 64441 264A68#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 Finishe$,ase'ent1 Stories1 !ar=et>alue* >AL0ES()211828)1 )2922 Lolita Dri3e)1 )Laurel)1 )!D)1 )64A4A)1 )Sin;le Fa'il")1 )-oo$)1 11 61 866265#44*. I(SERT I(T +ro/erties(A$$ress1 Cit"1 +ro/ert"T"/e1 ,e$roo's1 !ar=et>alue* >AL0ES()@446 +alas=o &C")1 )T"sons Corner)1 )Con$o'iniu')1 61 866?@5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 State1 7I+Co$e1 ,e$roo's1 <ear,uilt1 !ar=et>alue* >AL0ES()864115)1 )DC)1 )64411)1 61 1@?61 916555*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 Cit"1 7I+Co$e1 +ro/ert"T"/e1 ,e$roo's1 <ear,uilt1 !ar=et>alue* >AL0ES()@1A649)1 )AleBan$ria)1 )66468)1 )Sin;le Fa'il")1 91 1@251 985224#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 !ar=et>alue* >AL0ES()64481A)1 )8184 &olisto Crt)1 )-er'antoCn)1 )!D)1 )Con$o'iniu')1 )EBcellent)1 61 11 6158@5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()@6A8A8)1 )@566 Loc=Coo$ R$)1 )Che3" Chase)1 )!D)1 )64?56)1 )ToCnhouse)1 ),a$ Sha/e)1 91 6#51 91 41 91 1@@61 815225#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()64A?54)1 )18654 +ar=$oll R$)1 )Roc=3ille)1 )!D)1 )64?58)1 )ToCnhouse)1 )-oo$)1 91 6#51 61 11 61 1@??1 965@@5#44*. I(SERT I(T +ro/erties(Cit"1 +ro/ert"T"/e1 ,e$roo's1 <ear,uilt1 !ar=et>alue* >AL0ES()%ashin;ton)1 )ToCnhouse)1 81 1@A51 922AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 <ear,uilt1 !ar=et>alue* >AL0ES()6??584)1 )14984 &el'es Street D84?)1 )Sil3er S/rin;)1 )!D)1 )64@42)1 )Con$o'iniu')1 )-oo$)1 11 11 64441 686AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()68A8A6)1 )144? Co//en Street)1 )Sil3er S/rin;)1 )!D)1 )64@42)1 )Sin;le Fa'il")1 )EBcellent)1 91 91 91 11 91 1@@21 265854#44*. -
I(SERT I(T +ro/erties(Cit"1 7I+Co$e1 +ro/ert"T"/e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()Che3" Chase)1 )64@52)1 )Sin;le Fa'il")1 91 64411 565854#44*. I(SERT I(T +ro/erties(A$$ress1 Cit"1 State1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 !ar=et>alue* >AL0ES()2?2 &ero$ A3e DD48)1 )Ta=o'a +ar=)1 )!D)1 )Con$o'iniu')1 )EBcellent)1 61 924??5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()6@A882)1 )18445 Sni$ers ,l3$)1 )Laurel)1 )!D)1 )64A4A)1 )ToCnhouse)1 )(ee$s Re/air)1 81 1#51 91 11 61 64461 816??5#44*. I(SERT I(T +ro/erties(Cit"1 7I+Co$e1 Con$ition1 ,e$roo's1 Stories1 <ear,uilt* >AL0ES()Sil3er S/rin;)1 )64@45)1 )-oo$)1 81 61 1@25*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()@68A@6)1 )2?4 +rushia R$)1 )%ashin;ton)1 )DC)1 )6444?)1 )Sin;le Fa'il")1 )-oo$)1 51 9#51 91 41 91 64441 555??5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()6@8A@2)1 )182?? +arrison Street)1 )Colle;e +ar=)1 )!D)1 )64A86)1 )Sin;le Fa'il")1 )EBcellent)1 51 6#51 61 11 61 1@@51 8?5@@5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 <ear,uilt1 !ar=et>alue* >AL0ES()?11155)1 )14984 &el'es Street D1416)1 )Sil3er S/rin;)1 )!D)1 )64@42)1 )Con$o'iniu')1 )-oo$)1 11 11 64441 656AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()88A5@A)1 )8641 >ila'ar A3e)1 )&"atts3ille)1 )!D)1 )64A?6)1 )ToCnhouse)1 )EBcellent)1 91 61 61 11 91 1@@61 925??4#44*. I(SERT I(T +ro/erties(A$$ress1 7I+Co$e1 ,athroo's* >AL0ES()1266 Ro'bar$ Str)1 64@481 6#5*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()6@A815)1 )@?4 +horCic= Street)1 )%ashin;ton)1 )DC)1 )64448)1 )Sin;le Fa'il")1 )-oo$)1 81 9#51 91 91 11 64481 A958A5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1
7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()8A5@A8)1 )@415 !ar3in CroC A3e)1 )-aithersbur;)1 )!D)1 )64?A6)1 )Sin;le Fa'il")1 )(ee$s Re/air)1 81 6#51 91 11 11 1@251 215AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()?92286)1 )9412 Fel$'an Court)1 )Roc=3ille)1 )!D)1 )64@58)1 )Sin;le Fa'il")1 ),a$ Sha/e)1 51 91 91 11 91 1@241 56?555#44*. I(SERT I(T +ro/erties(Cit"1 State1 +ro/ert"T"/e1 Stories* >AL0ES()Roc=3ille)1 )!D)1 )ToCnhouse)1 1*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()64?948)1 )A94A E3erett &C")1 )%ashin;ton)1 )DC)1 )64416)1 )ToCnhouse)1 )EBcellent)1 61 6#51 61 41 81 64421 864554#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 <ear,uilt1 !ar=et>alue* >AL0ES()288118)1 )14984 &el'es StreetD1442)1 )Sil3er S/rin;)1 )!D)1 )64@42)1 )Con$o'iniu')1 )-oo$)1 61 61 64441 65?885#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()@9A@22)1 )A949 %ar:iel$ Court)1 )T"sons Corner)1 )>A)1 )66191)1 )Sin;le Fa'il")1 )-oo$)1 91 6#51 91 11 81 64421 ?65AA5#44*. I(SERT I(T +ro/erties(Cit"1 7I+Co$e1 Con$ition1 ,e$roo's1 Stories1 <ear,uilt* >AL0ES()Fair:aB)1 )66696)1 )-oo$)1 91 91 1@?5*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()6@A8@A)1 )16841 Conniar$ A3e)1 )Ta=o'a +ar=)1 )!D)1 )64@14)1 )ToCnhouse)1 )-oo$)1 91 6#51 91 11 91 64481 6?4AA5#44*. I(SERT I(T +ro/erties(Cit"1 7I+Co$e1 +ro/ert"T"/e1 ,e$roo's1 ,athroo's1 !ar=et>alue* >AL0ES()AleBan$ria)1 )66495)1 )Con$o'iniu')1 61 61 865AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 Cit"1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 <ear,uilt1 Stories1 !ar=et>alue* >AL0ES()?55655)1 )Laurel)1 )64A4A)1 )Sin;le Fa'il")1 )(ee$s Re/air)1 91 61 1@261 61 986?45#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 Cit"1 7I+Co$e1 +ro/ert"T"/e1
Con$ition1 ,e$roo's1 ,athroo's1 !ar=et>alue* >AL0ES()66566A)1 )Roc=3ille)1 )64?5A)1 )Con$o'iniu')1 )-oo$)1 11 11 565??5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()82@A54)1 )2168 Fal= R$)1 )Arlin;ton)1 )>A)1 )66491)1 )Sin;le Fa'il")1 )(ee$s Re/air)1 81 9#51 91 11 11 1@?61 295@@5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()?62@6A)1 )5161 Riehl Ace)1 )Fair:aB)1 )>A)1 )66696)1 )ToCnhouse)1 )EBcellent)1 91 1#51 61 41 11 64461 965264#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()6?A428 )1 )@599 +ensulian R$)1 )Sil3er S/rin;)1 )!D)1 )64@48)1 )Sin;le Fa'il")1 ),a$ Sha/e)1 91 1#51 91 11 61 1@@61 8?5AA5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 Cit"1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 <ear,uilt1 Stories* >AL0ES()A68441 )1 )A45 &elios A3e)1 )64448)1 )ToCnhouse)1 ),a$ Sha/e)1 91 1@A81 8*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()64@6A5)1 )@88 Fr"er A3e)1 )Che3" Chase)1 )!D)1 )64?56)1 )Sin;le Fa'il")1 )EBcellent)1 51 6#51 91 41 61 64461 265225#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()648A5@)1 )1@54 -ale;o Street)1 )-er'antoCn)1 )!D)1 )64?A8)1 )Sin;le Fa'il")1 )EBcellent)1 81 9#51 61 11 81 644A1 86?225#44*. I(SERT I(T +ro/erties(Cit"1 State1 +ro/ert"T"/e1 ,e$roo's1 ,athroo's1 <ear,uilt1 !ar=et>alue* >AL0ES()Ta=o'a +Ar=)1 )!D)1 )Conbo'iniu')1 61 61 64441 665??5#44*. I(SERT I(T +ro/erties(+ro/ert"(u'ber1 A$$ress1 Cit"1 State1 7I+Co$e1 +ro/ert"T"/e1 Con$ition1 ,e$roo's1 ,athroo's1 Finishe$,ase'ent1 In$oor-ara;e1 Stories1 <ear,uilt1 !ar=et>alue* >AL0ES()@9A65@)1 )16922 FoCler A3e)1 )AleBan$ria)1 )>A)1 )66491)1 )ToCnhouse)1 )-oo$)1 91 1#51 91 11 91 644A1 846?15#44*. -
6. 0ress F< to e)ecute <. "a e the file as 7eal(state. and close the query window
SQL Data
Analysis
After entering the "#L statement, you can e)ecute it to see the result. This would display the Table window. The result would be displayed in the bottom section. There are two ways you can display the result. To ha e access to these options, you can first display the display the "#L (ditor toolbar,
On the main menu, you can click =iew *; Toolbars *; "#L (ditor 9ou can right*click any toolbar and click "#L (ditor
To specify how you want to show the results of your "#L statement, you ha e two options,
To show the result as te)t, on the "#L (ditor toolbar, you can click the 7esult To Te)t button . Alternati ely, you can right*click somewhere in the table, position the mouse on 7esults To, and click 7esults To Te)t. The results would appear in two columns of te)t. +ere is an e)ample,
To show the result as a spreadsheet, on the "#L (ditor toolbar, you can click the 7esult To >rid button . Alternati ely, you can right*click somewhere in the table, position the mouse on 7esults To, and click 7esults To >rid. The results would appear as a spreadsheet of one or arious columns. +ere is an e)ample,
In either the Table window or the query window, you are e)pected to write appropriate code that would constitute a "#L statement. 0ractical Learning, 1reating a #uery .. In the Ob'ect ()plorer, right*click the $atabases node and click 7efresh /. ()pand the $atabases node 2. ()pand 7eal(state. 6. 7ight*click 7eal(state. and click :ew #uery Field "election The most fundamental keyword used by "#L is SELECT. In order to process a request, you must specify what to select. To perform data analysis, the SELECT keyword uses the following synta),
SELECT What FR ! WhatObject;
As stated already, "#L is not case*sensiti e. That means SELECT, Select, and select represent the same word. To select e erything from a table, you can use the asterisk as the range of alues. For e)ample, to display all
SELECT * FR ! Stu$ents.
After writing the e)pression, you must e)ecute the "#L statement to see its result. +ere is an e)ample,
9ou can also qualify the ? selector by preceding it with the name of the table followed by the period operator. The abo e statement is equi alent to,
SELECT Stu$ents#* FR ! Stu$ents.
In Lesson @, we saw that you could create an alias for a table by preceding a column with a letter or a word and a period operator, and then entering the name of the table followed by that letter or word. 5sing this feature, the abo e statement can be written as,
SELECT st$#* FR ! Stu$ents st$.
As opposed to iewing all data, you can also select one particular column whose fields you want to iew. To do this, you can replace the What in our synta) with the name of the desired column. For e)ample, to get a list of last names of statement,
SELECT Last(a'e FR ! Stu$ents.
9ou can also qualify a column by preceding it with the name of the table followed by the period operator. The abo e statement is equi alent to,
SELECT Stu$ents#Last(a'e FR ! Stu$ents.
%hen you e)ecute the statement, it would display only the column that contains the last names. To consider more than one column in a statement, you can list them in the What factor of our synta), separating them with a comma e)cept for the last column. The synta) you would use is,
SELECT Column11 Column21 Column_n FR ! WhatObject;
For e)ample, to display a list that includes only the names, gender, (mail address and home
Once again, you can qualify each column by preceding it with the name of the table followed by the period operator. The abo e statement is equi alent to,
SELECT Stu$ents#First(a'e1 Stu$ents#Last(a'e1 Stu$ents#-en$er1 Stu$ents#E'ailA$$ress1 Stu$ents#&o'e+hone FR ! Stu$ents.
9ou don8t ha e to qualify all columns, you can qualify some and not qualify some others. The abo e statement is equi alent to,
SELECT Stu$ents#First(a'e1 Last(a'e1 Stu$ents#-en$er1 E'ailA$$ress1 &o'e+hone FR ! Stu$ents.
Once again, remember that you can use an alias name for a table by preceding each column with a letter or a word and a period operator, and then entering the name of the table followed by that letter or word. +ere is an e)ample,
SELECT st$#First(a'e1 st$#Last(a'e1 st$#-en$er1 st$#E'ailA$$ress1 st$#&o'e+hone FR ! Stu$ents st$.
0ractical Learning, "electing $ata .. In the query window, type the following,
0SE RealEstate1. SELECT /#* FR ! +ro/erties /. -
/. 0ress F< to e)ecute the statement 2. To get a list of the properties numbers and their type, change the statement as follows,
SELECT $bo#+ro/erties#+ro/ert"(u'ber1
$bo#+ro/erties#+ro/ert"T"/e FR ! +ro/erties. -
6. 0ress F< to e)ecute <. To get a list of the types of properties, the year each was built, and its
market
A. 7ight*click somewhere in the table, position the mouse on 7esults To, and click 7esults To Te)t B. 0ress F< to e)ecute 5sing an Alias :ame for a 1olumn Introduction In your SELECT statement, after specifying the column3s4 as we ha e done so far, when you e)ecute the "#L statement, the name of each column would appear as the column header. Fortunately, you can display any string of your choice for a column header. To specify a column header other than the name of the column, if you are using the Table window, type the desired string in the Alias column corresponding to the column. +ere is an e)ample,
If you are using a query window or if you are your SELECT statement, on the right side of the column name, type AS followed by the desired name of the column header. If the desired column header is in one word, you can simply type it. +ere is an e)ample,
SELECT First(a'e1 Last(a'e1 &o'e+hone AS +hone(u'ber1 +arents(a'es AS (a'es :+arents FR ! Stu$ents. -
writing
If you want the column header to appear with more than one word, you can pro ide the words as a string in single*quotes or between the square brackets, C and D . +ere is an e)ample,
SELECT First(a'e AS EFirst (a'eF1 Last(a'e AS ELast (a'eF1 &o'e+hone AS E+hone (u'berF1 +arents(a'es AS E(a'es o: +arentsF FR ! Stu$ents. -
-y qualifying each column, the abo e statement can also be written as follows,
SELECT Stu$ents#First(a'e AS EFirst (a'eF1 Stu$ents#Last(a'e AS ELast (a'eF1 Stu$ents#&o'e+hone AS E+hone (u'berF1 Stu$ents#+arents(a'es AS E(a'es o: +arentsF FR ! Stu$ents. -
SELECT $bo#Stu$ents#First(a'e AS EFirst (a'eF1 $bo#Stu$ents#Last(a'e AS ELast (a'eF1 $bo#Stu$ents#&o'e+hone AS E+hone (u'berF1 $bo#Stu$ents#+arents(a'es AS E(a'es o: +arentsF FR ! Stu$ents. -
0ractical Learning, 5sing Alias :ames .. To use the alias names of columns, change the statement as follows,
SELECT house#+ro/ert"(u'ber AS E+ro/ DF1 house#7I+Co$e AS ELocationF1 house#<ear,uilt AS E<ear ,uiltF1 house#+ro/ert"T"/e AS ET"/eF1 house#,e$roo's AS E,e$sF1 house#,athroo's AS E,athsF1 house#!ar=et>alue AS E>alueF FR ! +ro/erties house. -
/. 7ight*click somewhere in the table, position the mouse on 7esults To, and click 7esults To >rid 2. 0ress F< to e)ecute A 1ombination or ()pression of 1olumns 5sing the SELECT keyword, we ha e learned to create a list of isolated columns. These columns were rendered separate of each other. Instead of ha ing separate columns, you can combine them to create a string or a alue that is in fact an e)pression. For e)ample, you can combine a first name and a last name to produce a full name as an e)pression. Another e)pression can use a date on the table, add a number to it to get a date on another day. An e)pression can also be used to perform a calculation on two or more columns such as
The most common operator used is the addition. It can be used to combine two or more strings to get a new one. +ere is an e)ample,
The addition can also be used on numeric alues. All other arithmetic operators can be used. For e)ample, you can multiply a weekly hours alue to an hourly salary to get a weekly salary. The statement of such an e)pression can be written as follows,
SELECT %ee=l"&ours * &ourl"Salar" FR ! +a"roll
9ou can also create an alias for an e)pression to gi e it the desired name. To do this, on the right side of the e)pression, type A" followed by the name. A" we learned earlier, if the alias is in more than one word, include it in either single
SELECT First(a'e G ) ) G Last(a'e AS )Full (a'e)1 E'r;(a'e G ) ) G E'r;+hone AS EE'er;enc" ContactF FR ! Stu$ents. -
The Assignment Operator If you 'ust create a regular e)pression using arithmetic operators, the new column would not ha e a name. The "#L allows you to specify a different name for any column during data analysis or a name for an e)pression. This is done using the assignment operator EFE. To change the name of a column during data analysis, on the right side of SELECT, type the desired name, followed by the assignment operator, followed by the actual name of the column. +ere is an e)ample,
SELECT E'er;enc"(a'e = E'r;(a'e FR ! Stu$ents. -
If you want to use more than one column, type each and assign it the desired name, separate them with commas. +ere is an e)ample,
SELECT Last(a'e1 E'er;enc"(a'e = E'r;(a'e1 E'er;enc"+hone = E'r;+hone
FR ! -
Stu$ents.
9ou can also include the name between single*quotes or the square brackets. +ere are e)amples,
SELECT Last(a'e G )1 ) G First(a'e AS EFull (a'eF1 EE'er;enc" (a'eF = E'r;(a'e1 )E'er;enc" +hone) = E'r;+hone FR ! Stu$ents. -