OK, I have worked out what distinct and distinctrow is doing. BUT it doesnt
solve my problem. the records i need to display are employee1 status=complete
and award may be award1 or award 2
So if I use the select distinct as a sub query (or as the main query?) , how
do I do that? Dont know how to work subqueries, despite reading a lot about
them this afternoon! Can I limit the employee ids in the main query to only
those specified by the select distinct query? I I am getting very weary of
this one and am on the verge of giving up completely. Can anyone help
further????
>OK, I have worked out what distinct and distinctrow is doing. BUT it doesnt
>solve my problem. the records i need to display are employee1 status=complete
[quoted text clipped - 6 lines]
>this one and am on the verge of giving up completely. Can anyone help
>further????
You haven't posted your table structure or the SQL of your attempts so
this can't be very precise, but I can give you a couple of
suggestions.
Perhaps simplest to understand is a method using two Queries. Create a
Query which selects the employee ID (and NOTHING ELSE) of the
employees that you want to count; uncheck the "show" checkbox in the
query grid for the award and status fields, since you're only using
them as criteria.
View the query's Properties and select "Unique Values".
The SQL will be something like
SELECT DISTINCT EmployeeID
FROM Employees
WHERE <various criteria>
Save this query (which will look very uninteresting, just a list of
ID's) as qryDistinctEmployees.
Now base a second query ON THIS QUERY; make it a totals query and
Count employeeID.
The Subquery method needs to use the SQL from the stored first query.
It's probably easiest to build that query first, open it in SQL view,
and copy and paste the SQL to a query (also in the SQL window) like
SELECT Count(*) FROM (<paste the query here>);
John W. Vinson[MVP]
lynn atkinson - 08 Dec 2005 11:03 GMT
OK thanks for that. Getting closer!
Here is the sql of the original query
SELECT progress.status, progress.[candidate ID], progress.[start date],
progress.award, employeeinfo.surname, employeeinfo.forename,
employeeinfo.title, employeeinfo.[post/role], employeeinfo.Project,
employeeinfo.locality, employeeinfo.[old contract],
Count(employeeinfo.[employee ID]) AS [CountOfemployee ID]
FROM employeeinfo INNER JOIN progress ON employeeinfo.[employee ID] =
progress.[employee id]
GROUP BY progress.status, progress.[candidate ID], progress.[start date],
progress.award, employeeinfo.surname, employeeinfo.forename,
employeeinfo.title, employeeinfo.[post/role], employeeinfo.Project,
employeeinfo.locality, employeeinfo.[old contract]
HAVING (((progress.status)="completed") AND ((progress.award)="care 4") AND
((employeeinfo.[post/role])="locality manager" Or
(employeeinfo.[post/role])="project manager") AND ((employeeinfo.[old
contract])=False)) OR (((progress.status)="completed") AND
((progress.award)="management 4") AND ((employeeinfo.[post/role])="locality
manager" Or (employeeinfo.[post/role])="project manager") AND
((employeeinfo.[old contract])=False));
iI need to put in the select distinct query - after the count bit? Do I
replace the FROM statement as it stands?
the select distinct query is
SELECT DISTINCT progress.[employee id]
FROM progress
WHERE (((progress.status)="completed") AND ((progress.award)="care 4")) OR
(((progress.status)="completed") AND ((progress.award)="management 4"));
I have obviously put it in the wrong place because I am now getting a
message about the level reserved word etc.....
Can I have 2 FROM statements or do I replace the FROM in the existing query?
Cheers
> >OK, I have worked out what distinct and distinctrow is doing. BUT it doesnt
> >solve my problem. the records i need to display are employee1 status=complete
[quoted text clipped - 38 lines]
>
> John W. Vinson[MVP]