Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

14
Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse

Transcript of Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Page 1: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Databases Section 4: Select QueriesPresented By: Lindani Ncube

Based on Materials by: M Halse

Page 2: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Simple Select Queries A SIMPLE select query (can only be performed on one

table) can be used to: choose one column to display choose multiple columns to display from one able limit the data in one column with “Criteria” limit the data in multiple specific columns

Select queries vs. Simple select queries A select query retrieves data and values from one or more tables

where as a simple select query can only be performed on one table.

The results are displayed of both types of queries are displayed in a datasheet view.

Page 3: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Using the Query Wizard for asimple Select Query

Click on Query Wizard in the “Queries” group in the create tab of the ribbon

For both Simple select queries and normal select queries use the “Simple query wizard”

Page 4: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Using the Query Wizard for asimple Select Query

Page 5: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select Query inDesign View

Click on the Query design button in the Queries group of the Create tab on the Ribbon

A “Query Tools” Design tab appears on the Ribbon

Page 6: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select Query InDesign View

Add all the tables you need to perform your query. This can be one or more tables.

You can add more later by using the Show Table button

Page 7: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select QueryIn Design View

Either Click on the selection button on the design tab of the Ribbon,

OR Right‐click on the query background area. In the context

menu provided, choose Select Query from Query Type

OR

Page 8: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select Query InDesign View

This is what you will see when you have created your query in design view:

Page 9: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select Query inDesign View

Page 10: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

You can choose to sort (ascending[A-Z] or descending [Z-A]) byone or more Fields

You can choose whether you wanta column to be visible in the resultor not, even if you apply criteria tothe column

You can specifyselect criteria

Page 11: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Creating a Select Query inDesign View

This query is equivalent to the MySQL statement it creates behind the scenes:

SELECT Wines.Name, Wines.[White/Red/Rose], Wines.Type,Wines.PriceFROM WinesWHERE (((Wines.Price)<200))ORDER BY Wines.Name;

This can be viewed by choosing SQL View from the View button

Page 12: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Saving a Query Run the query by pressing the Run button. The results of the query look like this i.e. they will

be shown to you in datasheet view.

Remember to save your query with a name that will indicate

what data it extracts.

Page 13: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Editing a Query Double‐click on the query

in the Navigation Pane

Switch to Design View and then edit your query.

Remember to save if you want to keep the changes.

Page 14: Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.

Section 4 Summary Using the Query Wizard for a Select Query Creating a Select Query in Design View Saving a Query Editing a query