BTT101 – Unit 5 - Database/Microsoft Access Lesson 5 - Creating a Query You can design queries to present your data in whatever filtered or sorted manner you want. Queries allow you to save the criteria which you used/specified for future use. 1. Open Access (Blank database) 2. Save database as Databasepractice2 in your Database folder. 3. You now have to create a table from which we can then create a query 4. Click on CREATE tab 5. Click on ‘Table Design” (to create a customer table with ten records) 6. Enter Field Names as needed without any spaces and select suitable Data Type from drop down list. Please note that Access automatically sets up a first field called ID. Start typing your field names in the second line. Do not override the Access-generated ID field and leave it as the primary key. FirstName LastName TelephoneNumber DeliveryArea Order (when populating this field choose either Combo 1, Combo 2 or Combo 3) 7. Save (Ctrl & ‘S’) when done. 8. Save using an appropriate name 9. Customers Table now appears in the navigation pane under Tables. 10. Enter information into the table for 10 of your Customers To Create a Query: 1. Click on the table which you want to base your query on. 2. Then click on CREATE 3. Then on Query Design 4. The Show Table box opens up 5. Select the Table you want to use the query for then click on Add 6. Then click on Close to close Show Table box. 7. Once you select a Table the Query Tools tab becomes available in the Ribbon area. 8. The selected Table is where we get the data from to build our query. 9. We then simply ‘drag’ (hold down left side of mouse) this data to the bottom of the screen (rows area) 10. Example, if we wanted to show only first and last name we drag those columns from the Table to the bottom of the screen where the query is built/created. 11. You can build in a sorting element into your query. Example if you wanted to sort last name you select the sort row at the bottom of screen in the LastName field and choose ascending order. 12. Then click on Run ( ! icon). 13. You can also build in a filtering element into your query. Example if you wanted to only show customers let’s say Caledon click on the filter row and select Caledon. 14. Notice, in most cases, Access automatically puts quotation marks at beginning/end of your chosen criteria (”Caledon”). All text-based criteria must be inside quotations. 15. Then click on the Run icon again. 16. A query is now created that will show customers sorted by last name as well as a filter which will ONLY show customers from the Caledon area. 17. Click on the save icon to save your query for future use (save as CustomersfromCaledonQ) 18. The query (CustomerswfromCaledon) should now appear in the objects pane under Queries Important Note: Queries rely on the live data that is in the Table it was pulled from. Therefore if the data on the table is edited or changed the results of the query may be affected. To ensure that your query is pulling updated data it is a good idea to click on the Refresh All icon in the ribbon area.