Simple clear advice in plain English

Hands on: Taking a structured approach

Learn how a little SQL can go a very long way

Access has a great graphical query builder, which blew the socks off the opposition when first implemented and continues to provide an extremely efficient way of writing queries. One excellent feature is that it can show you the SQL code that equates to a query you’ve built graphically (choose SQL View from the first button in the bar during query design).

SQL (Structured Query Language) is another highly useful querying tool, even more flexible than the query builder. Knowing a little SQL can greatly extend your query-building skills.

As we run through these example queries, note that if you write one as shown and save it, Access will sometimes rewrite it for you. It will run either way - it’s just that Access’ version is more verbose and bracket-strewn.

SELECT queries
Very often, queries simply reduce the volume of data that we pull back from a table. Imagine a table of 20 fields (columns) and 1,000 rows. A SELECT query can reduce the number of columns we see in the answer table rows using this syntax in SQL:
SELECT (column name 1, column
name 2)
FROM (table name);

and, as an example,

SELECT FirstName, LastName
FROM People;

This selects two columns, FirstName and LastName, from the People table. You can also include the table name in the SELECT line:

SELECT People.FirstName,
People.LastName
FROM People;

This is the more verbose syntax displayed by Access if you create this query in the builder. The answer table contains a subset of columns from the original table. To reduce the number of rows, we add a filter by means of a WHERE clause.

For example, if we want to see just the rows where the entry in FirstName is Bill:

SELECT People.FirstName,
People.LastName
FROM People
WHERE (((People.
FirstName)=”Bill”));

Access is also mighty free with its brackets, as you can see above. In fact, none are obligatory and the last line also works written thus:
WHERE People.FirstName=”Bill”;
or even:
WHERE FirstName=”Bill”;

Article tags

Reader Comments

Parameters with dates

It is possible make the same with dates. (Access 2003) For example if the parameter is a date and is null what use a date like #01/01/2008# I tried but don't work Thanks and sorry for my english because i'm Spanish

Posted by Juan Antonio Gordo, 20 Oct 2008

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

PC Pitstop PC Matic

PC Pitstop PC Matic utility software

Computer cleaning and anti-virus combined

Excel worksheet error message screenshot

Why can’t I insert new rows and columns in Microsoft Excel?

A limit to the number or columns and rows in a spreadsheet causes problems

Editing a song in Hit 'n' Mix

Hit'n'Mix music-editing software

An innovative music program that lets you experiment with your favourite songs

Question & Answer

Q.How do I stop Windows 7 search?

> Read the answer

Q.Is it a genuine call from Microsoft?

> Read the answer

Q.How can I turn Autoplay back on?

> Read the answer

Best deals on the web

img

THREE E585 Mi-Fi Take it Away Mobile Broadband - 5GB allowance

£44.97- Buy it now

img

THREE Huawei E353u Take It Away Mobile Broadband - One Month Rolling Contract

£4.99- Buy it now

img

T-MOBILE 3G Pay As You Go iPad Micro SIM

£0.10- Buy it now

Great benefits for subscribers!

Poll

Which is your preferred web browser

Jargon Buster

Computing terms explained in plain English

VGA

Video Graphics Array. Standard socket for connecting a monitor to a computer.

Great shopping deals from Computeractive