Access SQL Feature Using SQL
Objectives Change the font or font size Include fields and criteria in SQL queries Use computed fields and built-in functions in SQL queries Sort the results in SQL queries
Objectives Use multiple functions in the same command Group the results in SQL queries Join tables in SQL queries Compare with Access-generated SQL
Opening a Database Click the Start button on the Windows taskbar, point to All Programs on the Start menu, point to Microsoft Office on the All Programs submenu, and then click Microsoft Office Access 2003 on the Microsoft Office submenu If the Access window is not maximized, double-click its title bar to maximize it If the Language bar appears, right-click it and then click Close the Language bar on the shortcut menu
Opening a Database Click Open on the Database toolbar, and then click Local Disk (C:) in the Look in box. Double-click the Data folder, and then make sure the Ashton James College database is selected Click the Open button If the Security Warning dialog box appears, click the Open button When the Switchboard appears, close the Switchboard by clicking its Close button
Changing the Font Size Click Tools on the menu bar, and then click Options on the Tools menu Click the Tables/Queries tab Click the Size box arrow, and then click 10 in the list that appears Click the OK button
Changing the Font Size
Creating a New SQL Query If necessary, click the Queries object and then click the New button on the Database window toolbar Be sure Design View is selected and then click the OK button When the Show Table dialog box appears, click its Close button Be sure the Query1 : Select Query window is maximized Click the View button arrow and select SQL View
Creating a New SQL Query
Including Only Certain Fields Type SELECT [Client Number],[Name],[Amount Paid],[Current Due] as the first line of the command, and then press the ENTER key Type FROM [Client]; as the second line Click the Run button
Including Only Certain Fields
Preparing to Enter a New SQL Query Click the View button arrow Click SQL View
Including All Fields Delete the current command, type SELECT * as the first line of the command, and then press the ENTER key Type FROM [Client]; as the second line Click the Run button
Including All Fields
Using a Criterion Involving a Numeric Field Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE [Current Due]=0; as the third line Click the Run button
Using a Criterion Involving a Numeric Field
Using a Criterion Involving a Text Field Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE [City]='Lake Hammond'; as the third line Click the Run button
Using a Criterion Involving a Text Field
Using a Compound Criterion Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE [City]='Lake Hammond' as the third line, and then press the ENTER key Type AND [Current Due]=0; as the fourth line and then click the Run button
Using a Compound Criterion
Using NOT in a Criterion Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE NOT [City]='Lake Hammond'; as the third line Click the Run button
Using NOT in a Criterion
Using a Computed Field Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name],[Amount Paid]+[Current Due] AS [Total Amount] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE [Current Due]>0; as the third line Click the Run button
Using a Computed Field
Sorting the Results Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name],[Amount Paid],[Current Due],[Trainer Number] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type ORDER BY [Trainer Number],[Amount Paid]; as the third line Click the Run button
Sorting the Results
Using a Built-In Function Click the View button arrow, click SQL View, and then delete the current command Type SELECT COUNT(*) as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type WHERE [Trainer Number]='42'; as the third line Click the Run button
Using a Built-In Function
Using Multiple Functions in the Same Command Click the View button arrow, click SQL View, and then delete the current command Type SELECT COUNT(*),SUM([Amount Paid]) as the first line of the command, and then press the ENTER key Type FROM [Client]; as the second line Click the Run button
Using Multiple Functions in the Same Command
Using Grouping Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Trainer Number],SUM([Amount Paid]) AS [Total Paid],SUM([Current Due]) AS [Total Due] as the first line of the command, and then press the ENTER key Type FROM [Client] as the second line, and then press the ENTER key Type GROUP BY [Trainer Number] as the third line, and then press the ENTER key Type ORDER BY [Trainer Number]; as the fourth line and click the Run button
Using Grouping
Restricting the Groups that Appear Click the View button arrow and then click SQL View Click the beginning of the fourth line (ORDER BY [Trainer Number];), and then press the ENTER key Click the beginning of the new blank line, and then type HAVING SUM([Current Due])>3000 as the new fourth line Click the Run button
Restricting the Groups that Appear
Joining Tables Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Client Number],[Name],[Client].[Trainer Number],[First Name],[Last Name] as the first line of the command, and then press the ENTER key Type FROM [Client],[Trainer] as the second line, and then press the ENTER key Type WHERE [Client].[Trainer Number]=[Trainer].[Trainer Number]; as the third line Click the Run button
Joining Tables
Restricting the Records in a Join Click the View button arrow, and then click SQL View If necessary, click immediately after the semicolon on the third line Press the BACKSPACE key to delete the semicolon, and then press the ENTER key Type AND [Current Due] > 0; as the fourth line Click the Run button
Restricting the Records in a Join
Joining Multiple Tables Click the View button arrow, click SQL View, and then delete the current command Type SELECT [Course Offerings].[Client Number], [Name],[Course Offerings].[Course Number],[Course Description], as the first line of the command, and then press the ENTER key Type [Total Hours],[Hours Spent] as the second line of the command, and then press the ENTER key Type FROM [Course Offerings],[Course],[Client] as the third line, and then press the ENTER key
Joining Multiple Tables Type WHERE [Course].[Course Number]=[Course Offerings].[Course Number] as the fourth line, and then press the ENTER key Type AND [Client].[Client Number]=[Course Offerings].[Client Number]; as the fifth line Click the Run button. Resize each column to best fit the data by double-clicking the right edge of its field selector
Joining Multiple Tables
Closing the Query and Restoring the Font Size Click the Close Window button for the Microsoft Access - [Query1 : Select Query] window Click Tools on the menu bar, and then click Options on the Tools Menu. Click the Tables/Queries tab Click the Size box arrow, and then click 8 in the list that appears. Click the OK button
Closing a Database and Quitting Access Click the Close Window button for the Ashton James College : Database window Click the Close button for the Microsoft Access window
Summary Change the font or font size Include fields and criteria in SQL queries Use computed fields and built-in functions in SQL queries Sort the results in SQL queries
Summary Use multiple functions in the same command Group the results in SQL queries Join tables in SQL queries Compare with Access-generated SQL
Access SQL Feature Complete