At most one record can be returned by this subquery. (Error 3354)

Falcon88

Registered User.
Local time
Today, 17:46
Joined
Nov 4, 2014
Messages
309
Hiiiiiiii All Dears:

i have three tables as in the attached Picture ,

How to Know (query )for all employees that is not in this shift.
i try :
Code:
SELECT tblEmploees.EmploeeID, tblShiftEmploDetils.EmploeeNo, tblShiftEmploDetils.ShiftNo, tblEmploees.EmploeeName, 
(SELECT Dupe.EmploeeID
FROM tblEmploees AS Dupe LEFT JOIN tblShiftEmploDetils AS Dupe1 ON Dupe.EmploeeID = Dupe1.EmploeeNo
WHERE (((Dupe1.ShiftNo)=[Forms]![frmOrders]![subfrmShifts].[Form]![ShiftID]))) AS bff
FROM tblEmploees LEFT JOIN tblShiftEmploDetils ON tblEmploees.EmploeeID = tblShiftEmploDetils.EmploeeNo
GROUP BY tblEmploees.EmploeeID, tblShiftEmploDetils.EmploeeNo, tblShiftEmploDetils.ShiftNo, tblEmploees.EmploeeName;

but get "At most one record can be returned by this subquery. (Error 3354)"
 

Attachments

  • MNBFv.jpg
    MNBFv.jpg
    30.1 KB · Views: 129
Edit: I deleted some posts. So this is not what you got in your email.

If I understand what you want this query would show the employees on the shift selected in [Forms]![frmOrders]![subfrmShifts].[Form]![ShiftID]
Code:
SELECT tblShiftEmploDetils.EmploeeNo
FROM tblShiftEmploDetils
WHERE tblShiftEmploDetils.ShiftNo=1;

then you could use the in a WHERE NOT In clause like

Code:
SELECT DISTINCT tblEmploees.EmploeeID, tblEmploees.EmploeeName
FROM tblEmploees
WHERE  tblEmploees.EmploeeID Not In (
SELECT tblShiftEmploDetils.EmploeeNo
FROM tblShiftEmploDetils
WHERE tblShiftEmploDetils.ShiftNo= [Forms]![frmOrders]![subfrmShifts].[Form]![ShiftID] );

to show the employee not on that shift.

I think you can do this without the subquery. I'll see if I can come up with that version.
 
The way to do this that avoids the potentially slow subquery is to create a query that shows the employees on shift, e.g.

Code:
SELECT tblShiftEmploDetils.EmploeeNo
FROM tblShiftEmploDetils
WHERE (((tblShiftEmploDetils.ShiftNo)=[Forms]![frmOrders]![subfrmShifts].[Form]![ShiftID]));

Save this query as for example I named it qryEmployeesOnShift. Then you can use this in the query wizard to create an unmatched query. It will produce a query like:
Code:
SELECT tblEmploees.EmploeeID, tblEmploees.EmploeeName
FROM tblEmploees LEFT JOIN qryEmployeesOnShift ON tblEmploees.EmploeeID = qryEmployeesOnShift.EmploeeNo
WHERE (((qryEmployeesOnShift.EmploeeNo) Is Null));
 
The way to do this that avoids the potentially slow subquery is to create a query that shows the employees on shift, e.g.

Code:
SELECT tblShiftEmploDetils.EmploeeNo
FROM tblShiftEmploDetils
WHERE (((tblShiftEmploDetils.ShiftNo)=[Forms]![frmOrders]![subfrmShifts].[Form]![ShiftID]));
Save this query as for example I named it qryEmployeesOnShift. Then you can use this in the query wizard to create an unmatched query. It will produce a query like:
Code:
SELECT tblEmploees.EmploeeID, tblEmploees.EmploeeName
FROM tblEmploees LEFT JOIN qryEmployeesOnShift ON tblEmploees.EmploeeID = qryEmployeesOnShift.EmploeeNo
WHERE (((qryEmployeesOnShift.EmploeeNo) Is Null));


Very thanks , this is exactly what i want.
 

Users who are viewing this thread

Back
Top Bottom