Access Tutorial 5: Basic Queries using SQL



Similar documents
Access Tutorial 11: Action Queries

Access Tutorial 4: Basic Queries Using QBE

Access Tutorial 2: Tables

Access Tutorial 8: Combo Box Controls

Access Tutorial 3: Relationships

Access Tutorial 13: Event-Driven Programming Using Macros

Access Tutorial 14: Data Access Objects

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Access Tutorial 6: Form Fundamentals

Microsoft Access Tutorials: Table of Contents

Access Tutorial 9: Advanced Forms

Microsoft Access Lesson 5: Structured Query Language (SQL)

Knowledgebase Article

Access Tutorial 15: Advanced Triggers

SQL SELECT Query: Intermediate

Microsoft Access Tutorials: Table of Contents

Querying a Database Using the Select Query Window

Tutorial 4 - Attribute data in ArcGIS

Database Query 1: SQL Basics

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

9.1 SAS. SQL Query Window. User s Guide

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Toad for Data Analysts, Tips n Tricks

University of Arkansas Libraries ArcGIS Desktop Tutorial. Section 4: Preparing Data for Analysis

LESSON 7: IMPORTING AND VECTORIZING A BITMAP IMAGE

Social Relationship Analysis with Data Mining

Introduction to Microsoft Jet SQL

ADP Workforce Now V3.0

Introduction to tuple calculus Tore Risch

Guide to Performance and Tuning: Query Performance and Sampled Selectivity

Fireworks 3 Animation and Rollovers

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

KEYBOARD SHORTCUTS. Note: Keyboard shortcuts may be different for the same icon depending upon the SAP screen you are in.

Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu

Lab Manual. Databases. Microsoft Access. Peeking into Computer Science Access Lab manual

10 Listing data and basic command syntax

Information Design Tool User Guide SAP BusinessObjects Business Intelligence platform 4.0 Feature Pack 3

Appendix K Introduction to Microsoft Visual C++ 6.0

1.204 Lecture 3. SQL: Basics, Joins SQL

Customizing MISys Manufacturing Reports Using ADO-XML 6/3/2013

1 Using a SQL Filter in Outlook 2002/2003 Views. 2 Defining the Problem The Task at Hand

Talking to Databases: SQL for Designers

SQL Nested & Complex Queries. CS 377: Database Systems

EM L07 Thinking Outside the Box with Complex Software Licensing

Unit 3. Retrieving Data from Multiple Tables

This is a training module for Maximo Asset Management V7.1. It demonstrates how to use the E-Audit function.

Creating a multiple choice test in HyperStudio

Getting Started with Elastic DB Database Tools with Azure SQL

MS Access Lab 2. Topic: Tables

Automate tasks with Visual Basic macros

InstallShield Tip: Accessing the MSI Database at Run Time

Using SQL Queries in Crystal Reports

ABOUT THIS DOCUMENT ABOUT CHARTS/COMMON TERMINOLOGY

Qlik REST Connector Installation and User Guide

Tech Note 663 HMI Reports: Creating Alarm Database (WWALMDB) Reports

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Using AND in a Query: Step 1: Open Query Design

AnswerPath Version 5 User Guide Copyright 2014 Hindin Solutions Ltd. User Guide

Effective Use of SQL in SAS Programming

Chapter 10 Printing, Exporting, and ing

Stored Documents and the FileCabinet

XSLT Mapping in SAP PI 7.1

DiskPulse DISK CHANGE MONITOR

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

>

Getting Started with GRUFF

Creating QBE Queries in Microsoft SQL Server

EXPERT CHOICE TUTORIAL

DBQT - Database Query Tool Manual 1/11. Manual DBQT. Database Query Tool. Document Version: unu.ch

Installing C++ compiler for CSc212 Data Structures

Unit 21 - Creating a Button in Macromedia Flash

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Video Administration Backup and Restore Procedures

Introduction to scripting with Unity

Microsoft Access 2007

Database Studio is the new tool to administrate SAP MaxDB database instances as of version 7.5.

Setting up SQL Translation Framework OBE for Database 12cR1

Configuration example: Scene function in the actuator channel in the ETS. 1 Introduction

CREATE A 3D MOVIE IN DIRECTOR

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Welcome to the topic on queries in SAP Business One.

Programming with the Dev C++ IDE

COMP 110 Prasun Dewan 1

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Using Microsoft Access

SQL Server 2005 Reporting Services (SSRS)

Databases in Engineering / Lab-1 (MS-Access/SQL)

Access Tutorial 1 Creating a Database

Fibonacci Numbers and Greatest Common Divisors. The Finonacci numbers are the numbers in the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,...

Gates, Circuits, and Boolean Algebra

A Brief Introduction to MySQL

Connecting to SAP BW with Microsoft Excel PivotTables and ODBO

Chapter 3 Using Access Control Lists (ACLs)

Transcription:

Access Tutorial 5: Basic Queries using SQL 5.1 Introduction: The difference between QBE and SQL Query-By-Example (QBE) and Structured Query Language (SQL) are both well-known, industry-standard languages for extracting information from relational database systems. The advantage of QBE (as you saw in Tutorial 4) that it is graphical and relatively easy to use. The advantage of SQL is that it has achieved nearly universal adoption within the relational database world. With only a few exceptions (which you probably will not encounter in this assignment) QBE and SQL are completely interchangeable. If you understand the underlying concepts (projection, selection, sorting, joining, and calculated fields) of one, you understand the underlying concepts of both. In fact, in Access you can switch between QBE and SQL versions of your queries with the click of a mouse. Although you normally use QBE in Access, the ubiquity of SQL in organizations necessitates a brief overview. 5.2 Learning objectives What is the difference between QBE and SQL? How do I create an SQL query? 5.3 In this section, you will create a few simple queries in SQL. Create a new query but close the show table dialog box with out adding tables. Select View > SQL to switch to the SQL editor as shown in Figure 5.1. Michael Brydon (brydon@unixg.ubc.ca) Last update: 22-Aug-1997 Home Previous 1 o f 5

FIGURE 5.1: Open a query in SQL mode 5.3.1 Basic SQL queries A typical SQL statement resembles the following: SELECT DeptCode, CrsNum, Title FROM Courses WHERE DeptCode = COMM ; There are four parts to this statement: 1. SELECT <field 1, field 2,, field n > specifies which fields to project (the DIS- TINCTROW predicate shown in Figure 5.1 is optional and will not be discussed in this tutorial); 2. FROM <table> specifies the underlying table (or tables) for the query; 3. WHERE <condition 1 AND/OR condition 2,, AND/OR condition n > specifies one or more conditions that each record must satisfy in order to be included in the results set; 4. ; (semicolon) all SQL statements must end with a semicolon (but if you forget it, Access will add it for you). These can now be put together to build an SQL query: Type the following into the SQL window: SELECT DeptCode, CrsNum, Title FROM Courses WHERE DeptCode = COMM ; Select View > Datashee to view the results. Select View > Query Design to view the query in QBE mode, as shown in Figure 5.2. Save your query as qrycoursessql. Home Previous 2 o f 5

FIGURE 5.2: The SQL and QBE views are interchangeable. When you return to SQL mode after viewing your query in QBE mode, you will notice that Access has added some additional text. This optional text does not change the query in any way Home Previous 3 o f 5

5.3.2 Complex WHERE clauses You can use AND, OR, and NOT conditions in your WHERE clauses in a straightforward manner. Change your query to the following to get all Commerce courses with more than three credits: SELECT DeptCode, CrsNum, Title FROM Courses WHERE DeptCode = COMM AND Credits > 3 Note that since DeptCode is a text field, its criterion must be a string (in this case, the literal string COMM ). However, Credits is a numeric field and its criterion must be a number (thus, there cannot be quotation marks around the 3). 5.3.3 Join queries Join queries use the same elements as a basic select query. The only difference is that the FROM statement is replaced with a statement that describes the tables to be joined and the relationship (i.e., foreign key) between them:... FROM table 1 INNER JOIN table 2 ON table 1.field 1 = table 2.field 2... Note that since both tables contain the fields Dept- Code and CrsNum, the <table name>.<field name> notation must be used to remove any ambiguity. Create a new SQL query containing the text: SELECT Courses.DeptCode, Courses.CrsNum, Courses.Title, Sections.CatalogNum FROM Courses INNER JOIN Sections ON Courses.CrsNum = Sections.CrsNum Home Previous 4 o f 5

Discussion AND Courses.DeptCode = Sections.DeptCode WHERE Courses.DeptCode= COMM ; 5.4 Discussion Although the syntax of SQL is not particularly difficult, writing long SQL queries is tedious and errorprone. For this reason, you are advised to use QBE for the assignment. In the real world, however, when you say you know something about databases, it usually implies you know the data definition and data manipulation aspects of SQL in your sleep. If you plan to pursue a career in information systems, a comprehensive SQL reference book can be a worthwhile investment. Home Previous 5 o f 5