|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
A "for all" query in MS Access?
I have three tables, Equipment, LookUpGroups, and EquipmentGroups.
Equipment ---------- TagNumber LocationCode LookUpGroups ------------- GroupTagNumber TagNumber EquipmentGroups ---------------- GroupTagNumber I want my query to return the GroupTagNumber ONLY IF all of the TagNumbers in that group have a given LocationCode (Given by User). Example: GroupTagNumber: G1 TagNumber: A1 LocationCode: 1 GroupTagNumber: G1 TagNumber: A2 LocationCode: 2 GroupTagNumber: G2 TagNumber: A3 LocationCode: 1 So if the user enters LocationCode 1, then he should only get G2 back. I've started by trying to do a count query: Code:
SELECT tblEquipmentGroups.GroupTagNumber, tblEquipment.LocationCode FROM tblEquipmentGroups, tblEquipment, tblLookUpGroups WHERE tblEquipmentGroups.GroupTagNumber = tblLookUpGroups.GroupTagNumber AND tblEquipment.TagNumber = tblLookUpGroups.TagNumber GROUP BY tblEquipmentGroups.GroupTagNumber, tblEquipment.LocationCode But really I'm completely stuck. Any help/suggestions would be appreciated! Thanks, BB |
|
#2
|
|||
|
|||
|
Code:
SELECT GroupTagNumber from tblLookUpGroups lg where not exists(select * from tblEquipment te where te.TagNumber = lg.TagNumber and location_code <> <userGivenValue>) |
|
#3
|
|||
|
|||
|
Thanks for responding so quickly!
That almost works. it still returns both G1 & G2 though when the location code entered is 1. I've played around w/it a ton on my own and this is what I came up with (and *BONUS* it seems to work!): Code:
SELECT tblEquipmentGroups.GroupTagNumber FROM tblEquipmentGroups INNER JOIN (tblEquipment INNER JOIN tblLookUpGroups ON tblEquipment.TagNumber=tblLookUpGroups.TagNumber) ON tblEquipmentGroups.GroupTagNumber=tblLookUpGroups.GroupTagNumber GROUP BY tblEquipmentGroups.GroupTagNumber HAVING (((Avg(tblEquipment.LocationCode))=[Enter Location Code])); Wow, this has taken my whole morning! Thanks again for responding... I appreciate it immensely! BB |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > A "for all" query in MS Access? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|