Results 1 to 4 of 4
  1. #1
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40

    Prevent Group By eliminating duplicates

    I have a very simple query which takes the item name from one table and the amount received from another. Tables linked by Item Name. (Latter table imported hence item name field). I want to calculate the total received. As soon as click view totals the Group By eliminates duplicates. I wish to prevent this. If I select Output all fields then get error "cannot group on fields selected with *". I'm not using any wild cards to filter.



    Queries are used for more than one purpose so would prefer to limit number littering the db. Is there another way of preventing Group By eliminating duplicates please?

    Many thanks

    Pieter

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Queries are used for more than one purpose so would prefer to limit number littering the db. Is there another way of preventing Group By eliminating duplicates please?
    Why exactly are you clicking this if you do not want to combine like entries to get a total?
    Are you trying to maintain each individual record, while showing a grand total for each item?

    If so, do this in a series of two queries.
    First, create your aggregate query where you only have Item Name and Amount, and get your total of Amount (by using Group By to get rid of the duplicates).
    Then, link this query back to your original table, and you can "tack" on the Totals field to the end of each record, returning whatever fields you want.

    If you really want to do this in a single query, you can just nest the queries together. Just switch your first query to SQL View, and Copy and Paste the code out to somewhere (i.e. NotePad). Then open your second query, and in SQL View, replace the reference to your first Query in the join with the SQL code you Cut and Pasted out.

  3. #3
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40
    Thanks for coming back so quickly. For the sake of completeness for other viewers I'll explain what happened.

    The answer to your first question is that the query was nested in other queries and I didn't realise that dups were eliminated when the sum function wasn't used until today.

    A second query contained two Expressions and I assumed that I needed to select Expression in the Totals field in order for it to work. I declicked Totals and found the query still did its job and that showing Expression in the Total field wasn't needed. When I ran the report based on this query with Totals clicked it returned 343 lines because of dups removal. When I declicked Totals I had the full 12903 rows.

    Thanks for the help. I've noted the other solutions and the second one will come in useful. It's a trick that hasn't found its way into the manuals so far as I'm aware.

    Pieter

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Thanks for the help. I've noted the other solutions and the second one will come in useful. It's a trick that hasn't found its way into the manuals so far as I'm aware.
    Most Access manuals I have seen only show you how to use the Query Builder when creating queries. Most of them don't get into writing/editing the SQL Code directly. That is very powerful, as there are many things you cannot really do with the Query Builder, but you can do by writing the SQL code directly (like nesting queries and creating Union Queries).

    If you really want to become proficient at that, the best way is to learn to write SQL code directly.

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

Similar Threads

  1. Dlookup to prevent duplicates
    By arothacker in forum Access
    Replies: 16
    Last Post: 02-12-2014, 11:40 AM
  2. Replies: 10
    Last Post: 10-18-2012, 08:10 AM
  3. How to prevent duplicates in said example
    By raymondbeckham in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 03:29 PM
  4. Replies: 3
    Last Post: 02-10-2012, 11:34 AM
  5. Eliminating Duplicates in a Report
    By RedWolf3x in forum Reports
    Replies: 5
    Last Post: 10-21-2011, 10:42 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