Home  Fees/Services  Access Examples  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Query Examples
Select Distinct, Select Distinctrow, Select Top, Select All

Predicate Query: Top Percent All Distinct SQL Queries

Access Database Tutorials>SQL Queries>SQL Predicate Example

Download Access Program


Aggregate Functions
Child/Parent Table Query
Choose Function
SQL Choose Function +
Crosstab/Pivot Query
SQL Crosstab Query +
DateTime Query
SQL Delete Query
External Link to Tables
Filter Report Records
Group By Clause
Having Clause Query
Histogram Query
Insert Into Query/Append
Master/Detail Updates
SQL Order By Dynamic
Parameter Query
SQL Predicate Example
Self Join Query
Access Scalar Query
Select Statement
Select Top 1 Query
Union Query Example
Update Query Example


SQL Predicate Examples

SQL Predicates are simple but important to understand for full use of the query programming language.

  • Select All

  • Select Distinct

  • Select Distinctrow

  • Select Top

  • Select Top Percent

The ALL command is the default when you use a select statement:

Select * from Employees

is equivalent to entering

Select All * from Employees The Distinct command is often confused with the distinctrow keyword.  Here is an example of the difference:

Select Distinctrow Last_Name from Employees

This query won't necessarily retrieve a distinct list of employee last names.  If there are duplicates last names and ANY other field has different data between the two duplicate name records then you will get both records even though they have the same last name.  Whereas:

Select Distinct Last_Name from Employees

Will retrieve a unique list of employee last names because the Distinct command only looks at the fields you are returning in the query.  I have never had a reason to use the Distinctrow function because our tables never have duplicate rows.

Select TOP (aka Top Values/Top Values) is explained in an example page: Select Top 10 Records, but we will review it here combined with the PERCENT option:

Select Top 10 Last_Name from Employees
Order By Age desc

Using the Top 10 example tells the query engine to return 10 records, in this case it will be the 10 oldest employees.  Here is the percent option:

Select Top 10 Percent Last_Name from Employees Order By Age desc

In this case, if you had 1000 employees in the Employee table you would retrieve 100 records containing a list of the 100 oldest employees.

Now you know all about the use of predicates in the Microsoft Access programming language.


 

We now offer web-based SQL/Server application development in partnership with Integrated Databases, Inc. (new projects only).



Contact Information

SQL Queries
MS Access SQL Queries 2007 2003 2000  All Windows Versions