Learn about Subqueries in Access Courses Article Learn about Subqueries in Access Courses Article
    home | all categories | submit articles | about us | links | link to us | site map | contact us | recommended resources
 
Home » Articles » Computers » databases » Learn about Subqueries in Access Courses

Learn about Subqueries in Access Courses


By Christine Harrell

Learn about Subqueries in Access Courses

An understanding of queries is critical to database management. Without queries, you can't get at the information and the data is useless.

Once you master queries, a subquery is a powerful tool that greatly expands your abilities to get exactly the data you need. To unleash the real power of a subquery, you need to become familiar with SQL (pronounced "sequel"), the language of database queries. This type of knowledge, usually taught in advanced level Access courses and can make your database exponentially more powerful.

Subquery Basics
As you would learn in Access courses, a query in SQL is a SELECT statement. A subquery is simply a SELECT statement within a SELECT statement.

For example a simple query from our Access courses might read like this:

SELECT Employees.Name, Employees.Salary
FROM Employees;

This retrieves a list of employee names and their salaries from the Employees table.

A subquery from advanced Access courses could appear as such:

SELECT Employees.Name, Employees.Salary
FROM Employees
WHERE Employees.Salary IN
( SELECT TOP 5 Salary
FROM Employees AS Dupe
WHERE Dupe.Salary = Employees.Salary);

The main query pulls the same list of employees and their salaries. The subquery then takes from that list the five highest paid employees and puts them in a separate table aliased as Dupe.

Subqueries make it easy to perform such tasks as:

- Expressing values such as sales made in a given month as a percentage for all sales in the year
- List customers who haven't ordered in 60 days or employees who haven't made a recent sale
- Extract demographic data on customers from a specific state or city
- Calculate year to date totals
Problems With Subqueries

After learning how to create subqueries you will also learn some of the pitfalls to avoid.

Complex subqueries can perform quite slowly. If you find that performance is poor, try a stacked query instead. Make your first query then use the output table as the input table into the second query. Avoid nested subqueries (a query within a query within a query) as they can really drag down performance.

Subqueries that use the same table as the main query will require aliases, as demonstrated in the example above. The subquery uses the alias Dupe to make it clear it is referring to fields in the output of the main query and not in the main Employees table.

Sometimes Access just chokes on what seems to be a straightforward subquery. Verify the statement, confirming things like matching data types and that none of your names are on the reserved words list. Rewrite the query or, if necessary, break it into stacked queries.

Subqueries are incredibly powerful and flexible tools for data access but can also be a source of frustration and error if used incorrectly. Though they can be complicated, you may be amazed at how much more control you have over your data once you master this knowledge.



About the author

Author is a freelance copywriter. For more information on Access Courses, visit http://www.MicrosoftTraining.net/. from http://www.FreeArticlesAndContent.com

Copy This Article For FREE!!!

You can use this article and copy it on your own website for free! All you have to do is make sure the article is copied with no changes and includes the "About The Author" text. Also please ensure that all url's are hyperlinked according. Thank you.

Link To This Article - And We'll Link Back To Your Website!

You are more then welcome to link to this article! All you have to do is copy this webpage address from the address bar and create a link on your website. Please use the title of this article for your link text. Please get in contact once you have linked to this article and we'll link back to you! Thank you.
 
Other great articles from this category...


A Nightmare For SEO Hosting
Saturday, 1st March 2008

Get More Out of MS Access Courses
Sunday, 16th December 2007


Related Sites





Free Articles

Unsecured Credit Card Application   Free Proxy   Motorola MotoPEBL   Dog Training
Copyright © 2005-2008 Your Marketing Ltd. All Rights Reserved