Retrieve Selected Dates from Query

G

Guest

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
 
G

Guest

When I enter this in the Criteria line, I get an "invalid syntax" message.

Duane Hookom said:
Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


BillG said:
I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


BillG said:
When I enter this in the Criteria line, I get an "invalid syntax" message.

Duane Hookom said:
Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


BillG said:
I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





Duane Hookom said:
What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


BillG said:
When I enter this in the Criteria line, I get an "invalid syntax" message.

Duane Hookom said:
Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





Duane Hookom said:
What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


BillG said:
When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


Duane Hookom said:
I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





Duane Hookom said:
What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


BillG said:
Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


Duane Hookom said:
I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Actually, this was the second error. The first indicated that the syntax was
wrong and I needed to add parentheses around the SELECT statment. I did
that, and got the error referred to above.

This is the SQL the brought up the "you have written a subquery that can
return more than one field.....":

(SELECT Query1.[Case Number],Query1.[Begin Date]FROM Query1 WHERE
(((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date] FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY [Begin Date])))
ORDER BY Query1.[Case Number];)

Duane Hookom said:
Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


BillG said:
Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


Duane Hookom said:
I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

I'm not sure why you wrapped the entire statement in ()s.

SELECT Query1.[Case Number],Query1.[Begin Date]
FROM Query1
WHERE Query1.[Begin Date] In
(SELECT TOP 3 [Begin Date]
FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number]
ORDER BY [Begin Date])
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Actually, this was the second error. The first indicated that the syntax was
wrong and I needed to add parentheses around the SELECT statment. I did
that, and got the error referred to above.

This is the SQL the brought up the "you have written a subquery that can
return more than one field.....":

(SELECT Query1.[Case Number],Query1.[Begin Date]FROM Query1 WHERE
(((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date] FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY [Begin Date])))
ORDER BY Query1.[Case Number];)

Duane Hookom said:
Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


BillG said:
Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


:

I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

I just pasted what you wrote below into the Criteria field under the Begin
Date column...I got a message saying "the syntax in this subquery is
incorrect..check the subquery's syntax and enclose the subquery in
parentheses".




Duane Hookom said:
I'm not sure why you wrapped the entire statement in ()s.

SELECT Query1.[Case Number],Query1.[Begin Date]
FROM Query1
WHERE Query1.[Begin Date] In
(SELECT TOP 3 [Begin Date]
FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number]
ORDER BY [Begin Date])
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Actually, this was the second error. The first indicated that the syntax was
wrong and I needed to add parentheses around the SELECT statment. I did
that, and got the error referred to above.

This is the SQL the brought up the "you have written a subquery that can
return more than one field.....":

(SELECT Query1.[Case Number],Query1.[Begin Date]FROM Query1 WHERE
(((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date] FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY [Begin Date])))
ORDER BY Query1.[Case Number];)

Duane Hookom said:
Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


:

Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


:

I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

That was the full SQL statement, not just something to place in the criteria.
View the SQL view and paste in my suggestion.
--
Duane Hookom
Microsoft Access MVP


BillG said:
I just pasted what you wrote below into the Criteria field under the Begin
Date column...I got a message saying "the syntax in this subquery is
incorrect..check the subquery's syntax and enclose the subquery in
parentheses".




Duane Hookom said:
I'm not sure why you wrapped the entire statement in ()s.

SELECT Query1.[Case Number],Query1.[Begin Date]
FROM Query1
WHERE Query1.[Begin Date] In
(SELECT TOP 3 [Begin Date]
FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number]
ORDER BY [Begin Date])
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


BillG said:
Actually, this was the second error. The first indicated that the syntax was
wrong and I needed to add parentheses around the SELECT statment. I did
that, and got the error referred to above.

This is the SQL the brought up the "you have written a subquery that can
return more than one field.....":

(SELECT Query1.[Case Number],Query1.[Begin Date]FROM Query1 WHERE
(((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date] FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY [Begin Date])))
ORDER BY Query1.[Case Number];)

:

Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


:

Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


:

I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 
G

Guest

Eureka!!!!

Thanks for putting up with a real novice.

Duane Hookom said:
That was the full SQL statement, not just something to place in the criteria.
View the SQL view and paste in my suggestion.
--
Duane Hookom
Microsoft Access MVP


BillG said:
I just pasted what you wrote below into the Criteria field under the Begin
Date column...I got a message saying "the syntax in this subquery is
incorrect..check the subquery's syntax and enclose the subquery in
parentheses".




Duane Hookom said:
I'm not sure why you wrapped the entire statement in ()s.

SELECT Query1.[Case Number],Query1.[Begin Date]
FROM Query1
WHERE Query1.[Begin Date] In
(SELECT TOP 3 [Begin Date]
FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number]
ORDER BY [Begin Date])
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Actually, this was the second error. The first indicated that the syntax was
wrong and I needed to add parentheses around the SELECT statment. I did
that, and got the error referred to above.

This is the SQL the brought up the "you have written a subquery that can
return more than one field.....":

(SELECT Query1.[Case Number],Query1.[Begin Date]FROM Query1 WHERE
(((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date] FROM [Query1] B
WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY [Begin Date])))
ORDER BY Query1.[Case Number];)

:

Please provide the exact SQL that is causing this error.

--
Duane Hookom
Microsoft Access MVP


:

Well, now I'm getting an error message:


"You have written a subquery that can return more than one field without
using the EXISTS reserve word in the main query's FROM clause..."


:

I just re-created this query in the Northwind and it worked for me. Do you
have any records where Begin Date is null?

This is my exact SQL copied from a working query:

SELECT Query1.[Case Number], Query1.[Begin Date]
FROM Query1
WHERE (((Query1.[Begin Date]) In (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])))
ORDER BY Query1.[Case Number];

--
Duane Hookom
Microsoft Access MVP


:

Here's what I entered

SELECT * FROM [Query1] WHERE [Begin Date] IN (SELECT TOP 3 [Begin Date]
FROM [Query1] B WHERE [Query1].[Case Number] = B.[Case Number] ORDER BY
[Begin Date])

Query Name is Query1 Field Names are Begin Date and Case Number

The error message says "The syntax of the subquery is incorrect" ...check
the subquery's syntax and enclose the subquery in parentheses.

I appreciate your efforts here...you're working with a novice at best.





:

What exact sql did you try? Did you change the query name? Are the field
names correct? Did you really have spaces and symbols in your field names?

--
Duane Hookom
Microsoft Access MVP


:

When I enter this in the Criteria line, I get an "invalid syntax" message.

:

Try something like:

SELECT *
FROM [QueryName]
WHERE [Date of Service] IN
(SELECT TOP 3 [Date Of Service]
FROM [QueryName] B
WHERE [QueryName].[Case #] = B.[Case #]
ORDER BY [Date Of Service])
--
Duane Hookom
Microsoft Access MVP


:

I have a query that contains two tables: One contains Case Numbers for one
group of clients (children), the other contains case numbers and service
dates for all clients. The query asks to match case numbers from both tables,
and displays case number and service date for only the child clients:


Case # Date of Service

1 1/1/07
1 1/2/07
1 1/3/07
1 1/4/07
2 2/5/07
2 2/6/07
2 3/7/07
2 4/7/07
2 5/7/07

I want to retrieve only the first three
dates for each case number.

Any ideas?
 

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

Top