Results 1 to 2 of 2
  1. #1
    byterbit is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Location
    Noou Yauk
    Posts
    32

    distinct: why does just displaying a field return more records ? And how to stop ?

    3 queries, the 2nd one is "right"



    SELECT DISTINCT t.meter, contacts.METER, contacts.code
    FROM t INNER JOIN contacts ON t.meter = contacts.METER;
    18601 records


    SELECT DISTINCT t.meter, contacts.METER
    FROM t INNER JOIN contacts ON t.meter = contacts.METER;
    11434 records

    SELECT t.meter, contacts.METER
    FROM t INNER JOIN contacts ON t.meter = contacts.METER;
    18614 records

    Why does displaying the code in the first query return more records ?
    I thought "distinct" worked on the field just after "distinct"
    The second query is the "right" one, and gives me set I need; but I also need to see the codes !

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No, DISTINCT works on all fields in the SELECT clause. Your case is an example of why. There is clearly more than one code associated with a given meter, else you wouldn't get more records when you add code to the SELECT clause. How is Access to know which code to return when there are more than one? You may want to play with a totals query where you group on the meter fields and return the max (or whatever is appropriate) code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. stop access from auto adding records
    By svcghost in forum Forms
    Replies: 2
    Last Post: 10-21-2010, 05:25 PM
  2. Count distinct records in parameterized query
    By SilverSN95 in forum Access
    Replies: 5
    Last Post: 07-27-2010, 09:31 AM
  3. Return all records from Query
    By ysrini in forum Queries
    Replies: 1
    Last Post: 01-15-2010, 09:52 PM
  4. Return 0 if no records found
    By skwilliamson in forum Programming
    Replies: 1
    Last Post: 12-01-2009, 10:54 AM
  5. Replies: 2
    Last Post: 11-29-2009, 12:00 PM

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