sub query

S

Souris

Does MS Access support sub query?
I wanted to create a query which has sub query like following

Select MyField, (select MyField1 from mytable1 where mytable1.myfiled2 =
mytable.MyField3) from mytable


Do I need create 2 queries to do this or just one query with one sub query?

Your information is great appreciated,
 
J

John Spencer

Yes MS Access does support subqueries.

You will run into a problem if you plan to use a subquery in the FROM clause
and your table and field names don't conform to the naming convention of
only letters, numbers, and the underscore characters (with at least one
non-number character). Also you must avoid reserved words.

In addition, a subquery in the SELECT Clause can only return one value from
one row, so you normally need to use one of the aggregate functions in the
query to ensure that.

Select MyField
, (Select First(MyField1)
from mytable1
where mytable1.myfiled2 = mytable.MyField3) as xxx
from mytable

A subquery in the WHERE clause can only return one field, but many rows if
you use the In (or Exists) operator as the comparison operator.

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
S

Souris

Thanks for great information,

John Spencer said:
Yes MS Access does support subqueries.

You will run into a problem if you plan to use a subquery in the FROM clause
and your table and field names don't conform to the naming convention of
only letters, numbers, and the underscore characters (with at least one
non-number character). Also you must avoid reserved words.

In addition, a subquery in the SELECT Clause can only return one value from
one row, so you normally need to use one of the aggregate functions in the
query to ensure that.

Select MyField
, (Select First(MyField1)
from mytable1
where mytable1.myfiled2 = mytable.MyField3) as xxx
from mytable

A subquery in the WHERE clause can only return one field, but many rows if
you use the In (or Exists) operator as the comparison operator.

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

insert a crosstab in to temp table query 2
select top 5 4
query with zero records 6
Convert this Oracle Query to Access Query ? 2
access my field 1
sub query 16
Duplicates in Query 4
Append with Sub query 2

Top