Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum Rss Feed

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles

MS Access

Posted Dec 1, 2003

MS Access for the Business Environment: Access Query Techniques: Subqueries, Part 1

By William Pearson

About the Series ...

This article continues the series, MS Access for the Business Environment. The primary focus of this series is an examination of business uses for the MS Access relational database management system. The series is designed to provide guidance in the practical application of data and database concepts to meet specific needs in the business world. While the majority of the procedures I demonstrate will be undertaken with MS Access 2002, many of the concepts that we explore in the series will apply to other versions of MS Access.

For more information on the series, as well as the hardware / software requirements to prepare for the tutorials we will undertake, please see Tutorial 1: Create a Calculated Field with the Expression Builder.

Introduction to this Tutorial

While we have considered basic queries in past lessons, particularly as a basis for reporting and other topics, most of the queries we have encountered could have been assembled without writing "direct SQL." That is, they might have just as easily been constructed using the Design view, or perhaps even with the Query Builder, behind both of which MS Access constructs the SQL for us. There are, however, many cases where the SQL we need to handle real-world requirements cannot be assembled adequately with the Query Builder, or even within Design view. The MS Access documentation refers to several groups of these as "SQL-specific" queries, including pass-through, data definition, and union queries.

Subqueries are another group that requires special attention, and, while we can construct many of them within the query design grid, I find that situations requiring subqueries, as well as other sophisticated solutions, are best handled through the use of direct SQL. One of the best things about the SQL view in MS Access is that it allows us to "flip" from a query displayed / under construction in one of the two graphical modes to the actual SQL behind the scenes - and thus an excellent learning experience can be accessed by a simple click of the view button, which allows us to shift between Design, Datasheet, and SQL views within any query, and at any time, to suit our needs.

The objective of this lesson is to introduce subqueries within the context of MS Access, and to explore the creation and use of SQL subqueries to render a result dataset that meets an illustrative business need. To accomplish this, we will introduce the subquery, discussing its syntax in general as a part of overviewing its general use. Along with an introduction to the basic subquery, this lesson will include:

  • an examination of the syntax surrounding the use of the subquery;
  • an illustrative, hands-on example of the use of a subquery in a multi-step practice exercise;
  • a brief discussion of the results datasets that we obtain in each step of the practice example.

We will use the Northwind sample database that installs with MS Access for purposes of this lesson, in an attempt to make the lesson useful to virtually anyone who has access to MS Access.

MS Access Archives

Latest Forum Threads
MS Access Forum
Topic By Replies Updated
Help With Microsoft Access kasy 0 September 4th, 07:35 PM
Linked table not sorting or filtering - ODBC error Java 1 August 28th, 10:37 AM
Use Parameter in select statement (Sql in Microsoft Access) katty.jonh 1 July 25th, 06:45 AM
Query Issue algebroni 7 July 23rd, 04:22 PM