A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Unique Query in not working correctly ... too complex?



 
 
Thread Tools Display Modes
  #1  
Old December 26th, 2009, 03:00 AM posted to microsoft.public.access.queries
BobC[_6_]
external usenet poster
 
Posts: 89
Default Unique Query in not working correctly ... too complex?

I have 4 linked tables in Access 2007. 3 fo the tables contain a notes
field (SiteNotes, GroupNotes and EquipmentNotes. I want to create a
report that lists all notes. When I created an associated query I
cannot get it to be unique (it list multiple records that are identical.

The SQL is:
SELECT DISTINCT LocationTBL.LocationNumber, SiteTBL.SiteNumber,
SiteTBL.SiteNotes, CategoryGroupingTBL.GroupNotes,
EquipmentTBL.EquipmentNotes
FROM (LocationTBL INNER JOIN SiteTBL ON LocationTBL.ID =
SiteTBL.LocationID) INNER JOIN (CategoryGroupingTBL INNER JOIN
EquipmentTBL ON CategoryGroupingTBL.ID = EquipmentTBL.GroupID) ON
SiteTBL.ID = CategoryGroupingTBL.SiteID

WHERE (((EquipmentTBL.EquipmentNotes)"" And
(EquipmentTBL.EquipmentNotes) Is Not Null)) OR
(((CategoryGroupingTBL.GroupNotes)"" And
(CategoryGroupingTBL.GroupNotes) Is Not Null)) OR
(((SiteTBL.SiteNotes)"" And (SiteTBL.SiteNotes) Is Not Null));

If I cut out 1 of the fields it becomes unique. I assume it is too
complex? Is there a better way to do this?
  #2  
Old December 26th, 2009, 05:47 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Unique Query in not working correctly ... too complex?

On Fri, 25 Dec 2009 22:00:45 -0500, BobC wrote:

I have 4 linked tables in Access 2007. 3 fo the tables contain a notes
field (SiteNotes, GroupNotes and EquipmentNotes. I want to create a
report that lists all notes. When I created an associated query I
cannot get it to be unique (it list multiple records that are identical.

The SQL is:
SELECT DISTINCT LocationTBL.LocationNumber, SiteTBL.SiteNumber,
SiteTBL.SiteNotes, CategoryGroupingTBL.GroupNotes,
EquipmentTBL.EquipmentNotes
FROM (LocationTBL INNER JOIN SiteTBL ON LocationTBL.ID =
SiteTBL.LocationID) INNER JOIN (CategoryGroupingTBL INNER JOIN
EquipmentTBL ON CategoryGroupingTBL.ID = EquipmentTBL.GroupID) ON
SiteTBL.ID = CategoryGroupingTBL.SiteID

WHERE (((EquipmentTBL.EquipmentNotes)"" And
(EquipmentTBL.EquipmentNotes) Is Not Null)) OR
(((CategoryGroupingTBL.GroupNotes)"" And
(CategoryGroupingTBL.GroupNotes) Is Not Null)) OR
(((SiteTBL.SiteNotes)"" And (SiteTBL.SiteNotes) Is Not Null));

If I cut out 1 of the fields it becomes unique. I assume it is too
complex? Is there a better way to do this?


Yes; use *one* Notes table with a NoteType field.

With your current three notes tables, you'll probably need to create a
subsidiary UNION query:

SELECT EquipmentTBL.GroupID, EquipmentTBL.EquipmentNotes AS Note, "Equipment"
AS NoteType
FROM EquipmentTBL
WHERE EquipmentNotes IS NOT NULL
UNION
SELECT CategoryGroupingTBL.GroupID, CategoryGroupingTBL.GroupNotes AS Note,
"Group" AS NoteType
FROM CategoryGroupingTBL
WHERE GroupNotesNotes IS NOT NULL
UNION
SELECT SiteTbl.GroupID, SiteTbl.SiteNotes AS Note, "Site" AS NoteType
FROM SiteTbl
WHERE SiteNotes IS NOT NULL


and join this to your main table.
--

John W. Vinson [MVP]
  #3  
Old December 27th, 2009, 04:00 AM posted to microsoft.public.access.queries
BobC[_6_]
external usenet poster
 
Posts: 89
Default Unique Query in not working correctly ... too complex?

Thanks for the recommendation.

I have never tried a Union Query before ... I'll respond back if I have
any problems.

Thanks!
Bob

John W. Vinson wrote:
On Fri, 25 Dec 2009 22:00:45 -0500, wrote:

I have 4 linked tables in Access 2007. 3 fo the tables contain a notes
field (SiteNotes, GroupNotes and EquipmentNotes. I want to create a
report that lists all notes. When I created an associated query I
cannot get it to be unique (it list multiple records that are identical.

The SQL is:
SELECT DISTINCT LocationTBL.LocationNumber, SiteTBL.SiteNumber,
SiteTBL.SiteNotes, CategoryGroupingTBL.GroupNotes,
EquipmentTBL.EquipmentNotes
FROM (LocationTBL INNER JOIN SiteTBL ON LocationTBL.ID =
SiteTBL.LocationID) INNER JOIN (CategoryGroupingTBL INNER JOIN
EquipmentTBL ON CategoryGroupingTBL.ID = EquipmentTBL.GroupID) ON
SiteTBL.ID = CategoryGroupingTBL.SiteID

WHERE (((EquipmentTBL.EquipmentNotes)"" And
(EquipmentTBL.EquipmentNotes) Is Not Null)) OR
(((CategoryGroupingTBL.GroupNotes)"" And
(CategoryGroupingTBL.GroupNotes) Is Not Null)) OR
(((SiteTBL.SiteNotes)"" And (SiteTBL.SiteNotes) Is Not Null));

If I cut out 1 of the fields it becomes unique. I assume it is too
complex? Is there a better way to do this?


Yes; use *one* Notes table with a NoteType field.

With your current three notes tables, you'll probably need to create a
subsidiary UNION query:

SELECT EquipmentTBL.GroupID, EquipmentTBL.EquipmentNotes AS Note, "Equipment"
AS NoteType
FROM EquipmentTBL
WHERE EquipmentNotes IS NOT NULL
UNION
SELECT CategoryGroupingTBL.GroupID, CategoryGroupingTBL.GroupNotes AS Note,
"Group" AS NoteType
FROM CategoryGroupingTBL
WHERE GroupNotesNotes IS NOT NULL
UNION
SELECT SiteTbl.GroupID, SiteTbl.SiteNotes AS Note, "Site" AS NoteType
FROM SiteTbl
WHERE SiteNotes IS NOT NULL


and join this to your main table.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:31 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.