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
Related articles
Q.How do I stop Windows 7 search?
Q.Is it a genuine call from Microsoft?
Q.How can I turn Autoplay back on?
|
|
|
|
|
Nikon Coolpix S570 BlackPrice: £66.99 |
Computeractive Ultimate Guide - Storage, Sharing & BackupPrice: £5.99 |
Back Issue CD-Rom 13 (2010)Price: £9.99 |
Hallmark Card Studio DeluxePrice: £15.31 |
Marine AquariumPrice: £15.41 |
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