Results 1 to 12 of 12
  1. #1
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6

    Removing duplicate entries in counting table items

    I use three connected tables, in one I have names of authors and data about authors, in the other table I have a list of books or articles these authors wrote. The two tables are linked with a third which allows me to correlate one article or book with multiple authors. The problem occurs when i need to count the total number of articles or books written. If an article or a book is written by two or more authors, Access counts it as two separate titles, so I need a way to avoid that and count every article or book as one item.

    Thanks in advance

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you are counting the total number of articles or books written you do not need the authors table, that would just leave you with the individual documents. Or are you saying when you see an article you want to see all authors associated with it but only as a single record?

  3. #3
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6

    Rephrasing

    Yep, I didn't express myself well, to count the total number of articles and books, I just have to count them in the articles and books list. But I will almost never have to do that,, it will always be connected with some criteria in the authors table, for example

    name city State
    Mark Chicago Usa
    Peter Chicago Usa
    Randy Paris France
    I would need to count all articles written by people from Chicago, and the problem appears if Mark and Peter wrote an article together, both of them are linked to the article and Access counts it as 2 articles, although it is in reality 1 article. Hope I made my problems a bit more clear

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    so, again, when you do counts of articles, you want each article to appear only once, but you want to show ALL authors associated with that article. If you do not need the authors related to the article for a particular query, then just don't include it to get your article count. If you DO want to see the authors that's another matter, that's what I'm trying to find out.

  5. #5
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6
    I want to be able to do both options, both with and without authors, but the same problems arises when I want so count some other criteria, for example the sum of all articles of people with a Phd. The Phd info is written in the authors table and so if I count the sum of articles written by people with a Phd, an article authored by two people appears twice in the table, as is it linked to both authors and it so counted twice.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    can you post a sample of your database, it would be easier to give you direction with your actual table structure.

    The problem you're encountering is a result of a 1 to many relationship, to counteract this you'd have to use an aggregate query or some other method to reduce your dataset to the desired number of records.

    For instance in the case of articles written by PhD people you would want an aggregate query (look for the Sigma button on your toolbar) and have a GROUP BY in all the article fields but have WHERE in the 'education level' field with a value of 'phd' or whatever your indicator is of the education level of the author.

    If you want an all purpose query that you can pose requests against you will likely need a temp table or a crosstab query with individual author information on it which could be incredibly cumbersome

  7. #7
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6
    I have succeeded in resolving all issues that I had using the aggregate query beside the trouble that appears when I try to count all publications written by assistants or full professors, using their names. If the name is not included the duplicate doesn't arise, but it does it the name is included. I'm posting the sheets below of a similar document with the same problem that I made and is in English, the original is not so no point in that, I would post the actual document, but it exceeds the limit so I can't upload it. I post all my tables, and a problematic query.
    ID Name Title Field
    1 John Smith full prof philosophy
    2 Jim Brown assistant prof english language
    3 Mark Roberts assoc prof english language
    5 Steven Clark full prof philosophy

    ID Name Type Place of publication
    3 name 1 Article Chicago
    4 name 2 book Paris
    5 name 3 book Chicago
    6 name 4 book London
    ID Author ID Publication ID
    3 1 3
    4 1 4
    5 1 5
    6 2 3
    7 2 6
    9 3 4
    10 3 5
    14 5 6
    Author.Name Field Publication.Name Type Place of publication
    John Smith philosophy name 1 Article Chicago
    John Smith philosophy name 2 book Paris
    John Smith philosophy name 3 book Chicago
    Steven Clark philosophy name 3 book Chicago
    as you see, the publication I named name 3 appears twice and it would be ideal if it could appear only once stating just it's authored by 2 people

    Thanks a lot for the help so far and thanks in advance for any suggestions on this issue

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    so... one more time... you still haven't answered the question I'm after so I will try to be as clear as I can

    assuming the last query is the one you want, for the book NAME 3, do you want to see ALL authors (the names), or do you just want to see 'x many authors'.

    Author.Name Field Publication.Name Type Place of publication
    John Smith philosophy name 1 Article Chicago
    John Smith philosophy name 2 book Paris
    John Smith philosophy name 3 book Chicago
    Steven Clark philosophy name 3 book Chicago

    This was your original

    Do you want this:

    Author.Name Field Publication.Name Type Place of publication
    John Smith philosophy name 1 Article Chicago
    John Smith philosophy name 2 book Paris
    2 AUthors philosophy name 3 book Chicago


    OR THIS

    Author.Name Field Publication.Name Type Place of publication
    John Smith philosophy name 1 Article Chicago
    John Smith philosophy name 2 book Paris
    John Smith, Steven Clark philosophy name 3 book Chicago


    One is extremely easy (the first), the other is not so much which is why I need you to be clear on your need.

  9. #9
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6
    I am really sorry that we keep misunderstanding each other, (or I keep misunderstanding you), the second option would be ideal if you can explain to me, that would solve all of my problems I think

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    There isn't an elegant way to handle this. With a properly normalized structure what you're asking for is really the hardest thing to do (to me). There's the rub, you have the correct structure but what you want to get to makes a non-normalized structure a better alternative but then your tables will be carrying a lot of blank records and would make other searches harder so this is what I propose:

    Create a table called 'tblAuthorStrings', have the Document unique identifier as your primary key (just set the field to number) and a field called 'authorstring'

    create a query called qryDocAuthorProcessing based on your junction table linking documents to authors, include the author table, add the first and last name fields from the authors table, sort the table the document identifier FIRST, followed by last name of the author (ascending order) and first name of the author (ascending order)

    Next run a query like this either as part of your regular maintenance, or every time you update the table itself

    Code:
    Dim db As Database
    Dim rst As Recordset
    Dim sSQL As String
    Dim iPrevDoc As Long
    Dim iCurrDoc As Long
    Dim sAuthorString As String
    
    
    Set db = CurrentDb
    db.Execute ("DELETE * FROM tblAuthorStrings")
    
    
    Set rst = db.OpenRecordset("qryDocAuthorProcessing")
    iPrevDoc = rst!doc_id
    Do While rst.EOF <> True
        iCurrDoc = rst!doc_id
        If iCurrDoc <> iPrevDoc Then
            db.Execute ("INSERT INTO tblAuthorStrings (DocID, AuthorString) VALUES (" & iPrevDoc & ", '" & Left(sAuthorString, Len(sAuthorString) - 2) & "')")
            iPrevDoc = iCurrDoc
            sAuthorString = rst!authorfn & " " & rst!authorln & ", "
        Else
            sAuthorString = sAuthorString & rst!authorfn & " " & rst!authorln & ", "
        End If
        rst.MoveNext
    Loop
    
    
    db.Execute ("INSERT INTO tblAuthorStrings (DocID, AuthorString) VALUES (" & iCurrDoc & ", '" & Left(sAuthorString, Len(sAuthorString) - 2) & "')")
    
    
    Set db = Nothing
    This will populate tblAuthorStrings with the document identifier and one long string with the author names. use this table to retrieve your author names for query/reporting purposes NOT

  11. #11
    matepenava is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Location
    Mostar
    Posts
    6
    Thank you very much for your help, I'll try this option and see if it works out, if I don't succeed you have still helped a lot

    Greetings

  12. #12
    dcwaits is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Posts
    2
    In sql view add Distinct before the field where duplicate would occur

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-21-2014, 11:44 AM
  2. Replies: 8
    Last Post: 02-18-2014, 09:50 PM
  3. Prevent duplicate entries in linked table
    By arothacker in forum Forms
    Replies: 5
    Last Post: 02-11-2014, 11:08 PM
  4. Replies: 1
    Last Post: 12-09-2011, 07:34 AM
  5. Replies: 2
    Last Post: 04-20-2011, 06:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums