Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / May 2007

Tip: Looking for answers? Try searching our database.

Restrict Duplicates In A Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
perplexed - 22 May 2007 23:09 GMT
I have a query that combines two table.  The Schedule Table and the Daily
Journal Table. The relationship join is set to "Only Include Rows where the
join fields from both tables are equal. " Yet I am getting a duplicate record
of each (i.e. I have two records with mirror data of ID 2262; I assume one
for the schedule table and one for the daily journal table).  I have my
properties set for Unique Records: YES. My SQL Code looks like this: SELECT
DISTINCTROW [Table: Schedule].ID, [Table: Schedule].[Appt Date], [Table:
Schedule].[Appt Time], [Table: Schedule].Customer, [Table: Schedule].[PO #],
DAILY_JOURNAL.[PO #], [Table: Schedule].[Trucking Co], DAILY_JOURNAL.[Actual
Ship Date], DAILY_JOURNAL.[Appt Time], DAILY_JOURNAL.Customer,
DAILY_JOURNAL.[LOL Order Number], DAILY_JOURNAL.[Trucking Co],
DAILY_JOURNAL.[Orig Ship Date], DAILY_JOURNAL.[Checked - IN],
DAILY_JOURNAL.[Checked Out], DAILY_JOURNAL.Comments, DAILY_JOURNAL.[Order
Shipped On Time], DAILY_JOURNAL.[NFDM Incoming], DAILY_JOURNAL.[Freight
Incoming], DAILY_JOURNAL.[Pallets Incoming], DAILY_JOURNAL.[Pkg Incoming],
DAILY_JOURNAL.[Salt Incoming], DAILY_JOURNAL.[Trays Incoming],
DAILY_JOURNAL.[Rescheduled by Denmark], DAILY_JOURNAL.[Rescheduled by
Customer], DAILY_JOURNAL.[No Show], DAILY_JOURNAL.[Show/No Appt],
DAILY_JOURNAL.[Carrier Issue], DAILY_JOURNAL.[DELETE RECORD & APPT]
FROM [Table: Schedule] INNER JOIN DAILY_JOURNAL ON ([Table: Schedule].[PO #]
= DAILY_JOURNAL.[PO #]) AND ([Table: Schedule].[Appt Time] =
DAILY_JOURNAL.[Appt Time]) AND ([Table: Schedule].Customer =
DAILY_JOURNAL.Customer) AND ([Table: Schedule].[Appt Date] =
DAILY_JOURNAL.[Actual Ship Date])
GROUP BY [Table: Schedule].ID, [Table: Schedule].[Appt Date], [Table:
Schedule].[Appt Time], [Table: Schedule].Customer, [Table: Schedule].[PO #],
DAILY_JOURNAL.[PO #], [Table: Schedule].[Trucking Co], DAILY_JOURNAL.[Actual
Ship Date], DAILY_JOURNAL.[Appt Time], DAILY_JOURNAL.Customer,
DAILY_JOURNAL.[LOL Order Number], DAILY_JOURNAL.[Trucking Co],
DAILY_JOURNAL.[Orig Ship Date], DAILY_JOURNAL.[Checked - IN],
DAILY_JOURNAL.[Checked Out], DAILY_JOURNAL.Comments, DAILY_JOURNAL.[Order
Shipped On Time], DAILY_JOURNAL.[NFDM Incoming], DAILY_JOURNAL.[Freight
Incoming], DAILY_JOURNAL.[Pallets Incoming], DAILY_JOURNAL.[Pkg Incoming],
DAILY_JOURNAL.[Salt Incoming], DAILY_JOURNAL.[Trays Incoming],
DAILY_JOURNAL.[Rescheduled by Denmark], DAILY_JOURNAL.[Rescheduled by
Customer], DAILY_JOURNAL.[No Show], DAILY_JOURNAL.[Show/No Appt],
DAILY_JOURNAL.[Carrier Issue], DAILY_JOURNAL.[DELETE RECORD & APPT]
HAVING ((([Table: Schedule].Customer) Is Not Null))
ORDER BY [Table: Schedule].[Appt Date], [Table: Schedule].[Appt Time];

Any clues how I can fix this?
strive4peace - 23 May 2007 05:58 GMT
instead of DISTINCTROW, try DISTINCT

you would not want distinct records because you most likly have a
primary key on each row, so this will do nothing to limit the records.
Instead of Unique Records, you probably want Unique Values

I formatted the SQL to be easier to read:

SELECT DISTINCTROW [Table: Schedule].ID
    , [Table: Schedule].[Appt Date]
    , [Table: Schedule].[Appt Time]
    , [Table: Schedule].Customer
    , [Table: Schedule].[PO #]
    , DAILY_JOURNAL.[PO #]
    , [Table: Schedule].[Trucking Co]
    , DAILY_JOURNAL.[Actual Ship Date]
    , DAILY_JOURNAL.[Appt Time]
    , DAILY_JOURNAL.Customer
    , DAILY_JOURNAL.[LOL Order Number]
    , DAILY_JOURNAL.[Trucking Co]
    , DAILY_JOURNAL.[Orig Ship Date]
    , DAILY_JOURNAL.[Checked - IN]
    , DAILY_JOURNAL.[Checked Out]
    , DAILY_JOURNAL.Comments
    , DAILY_JOURNAL.[Order Shipped ON Time]
    , DAILY_JOURNAL.[NFDM Incoming]
    , DAILY_JOURNAL.[Freight Incoming]
    , DAILY_JOURNAL.[Pallets Incoming]
    , DAILY_JOURNAL.[Pkg Incoming]
    , DAILY_JOURNAL.[Salt Incoming]
    , DAILY_JOURNAL.[Trays Incoming]
    , DAILY_JOURNAL.[Rescheduled by Denmark]
    , DAILY_JOURNAL.[Rescheduled by Customer]
    , DAILY_JOURNAL.[No Show]
    , DAILY_JOURNAL.[Show/No Appt]
    , DAILY_JOURNAL.[Carrier Issue]
    , DAILY_JOURNAL.[DELETE RECORD & APPT]
FROM [Table: Schedule]
    INNER JOIN DAILY_JOURNAL
        ON ([Table: Schedule].[PO #] = DAILY_JOURNAL.[PO #])
    AND ([Table: Schedule].[Appt Time] = DAILY_JOURNAL.[Appt Time])
    AND ([Table: Schedule].Customer = DAILY_JOURNAL.Customer)
    AND ([Table: Schedule].[Appt Date] = DAILY_JOURNAL.[Actual Ship Date])
GROUP BY [Table: Schedule].ID
    , [Table: Schedule].[Appt Date]
    , [Table: Schedule].[Appt Time]
    , [Table: Schedule].Customer
    , [Table: Schedule].[PO #]
    , DAILY_JOURNAL.[PO #]
    , [Table: Schedule].[Trucking Co]
    , DAILY_JOURNAL.[Actual Ship Date]
    , DAILY_JOURNAL.[Appt Time]
    , DAILY_JOURNAL.Customer
    , DAILY_JOURNAL.[LOL Order Number]
    , DAILY_JOURNAL.[Trucking Co]
    , DAILY_JOURNAL.[Orig Ship Date]
    , DAILY_JOURNAL.[Checked - IN]
    , DAILY_JOURNAL.[Checked Out]
    , DAILY_JOURNAL.Comments
    , DAILY_JOURNAL.[Order Shipped ON Time]
    , DAILY_JOURNAL.[NFDM Incoming]
    , DAILY_JOURNAL.[Freight Incoming]
    , DAILY_JOURNAL.[Pallets Incoming]
    , DAILY_JOURNAL.[Pkg Incoming]
    , DAILY_JOURNAL.[Salt Incoming]
    , DAILY_JOURNAL.[Trays Incoming]
    , DAILY_JOURNAL.[Rescheduled by Denmark]
    , DAILY_JOURNAL.[Rescheduled by Customer]
    , DAILY_JOURNAL.[No Show]
    , DAILY_JOURNAL.[Show/No Appt]
    , DAILY_JOURNAL.[Carrier Issue]
    , DAILY_JOURNAL.[DELETE RECORD & APPT]
HAVING ((([Table: Schedule].Customer) Is Not Null))
ORDER BY [Table: Schedule].[Appt Date]
    , [Table: Schedule].[Appt Time];

Woah!  This is a lot of information.  I see you have a key field in
here: [Table: Schedule].ID -- this means you will automatically get all
records from [Table: Schedule] since you are including its key field.

You really should consider renaming your fields and tables to not
include special characters (like #, &, :, /, etc).  Personally I do not
even use spaces.  Underscore _ is okay.  Names should always start with
a letter

For more information, download and read this:

Access Basics
http://allenbrowne.com/tips.html
Tips for Casual Users
Access Basics: free tutorial - Word document by Crystal (Access MVP)

30-page Word document on Access Basics  -- it doesn't cover VBA, but
prepares you for it because it covers essentials in Access.  Pay close
attention to the section on Normalization.

Warm Regards,
Crystal
 *
     (:  have an awesome day  :)
  *
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
  *

> I have a query that combines two table.  The Schedule Table and the Daily
> Journal Table. The relationship join is set to "Only Include Rows where the
[quoted text clipped - 37 lines]
>
> Any clues how I can fix this?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.