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

Access Query Examples
Scalar Query with Aggregate Function Queries

Scalar SubQuery Example SQL Queries

Access Database Tutorials>SQL Queries>Scalar Query

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


Scalar Query in Access SQL

Access scalar query allows you to do in one SQL statement what you are used to doing in two or more queries.

This function allows retrieval of single values from a table, usually aggregate functions, from within the from clause.

Get individual values while at the same time getting max, min, avg, etc values from the same source without having to use the Group By clause... this greatly simplifies query design.  Here's the setup for our scalar query example:

Scalar SubQuery

Our goal is the retrieve SSN, Pay_Rate, Max Pay_Rate, Min Pay_Rate,  and calculate each employees' percent of maximum pay rate.

See the following SQL statement:

scalar subquery

Don't bother trying to create this in the  design grid.  You must get into SQL view.  The key point of the query is:

[select max(pay_rate) as Max_R from m_emp_pay]. as Q_Max   There are two aliases in this scalar subquery - Max_R for the field and Q_Max for the source name.   Not that an Access SQL alias is an typically an abbreviation for the table or calculated field name.  See how the alias is used in the Select clause of the query.  No group by required!!  Therefore you get the individual pay rates for employees while, at the same time, retrieving min, max, and most importantly the percent of max.

See the results of the scalar subquery below:

scalar subquery

The main restriction with scalar subquery SQL statement is that the function can only return a single value, although you can have multiple subquery statements in one main query.


 

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