Results 1 to 7 of 7
  1. #1
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91

    Union Query showing duplicates

    Hi, I am desparate for some help on this please, I am getting dupicate [Student_id] and [Student], I have managed to remove some with the where clause but not all. The code I have is below, please can some one tell me what is wrong with it?

    [SELECT DISTINCT FAMLSR16A.student_id, FAMLSR16A.Student, FAMLSR16A.learn_sup_1a AS learn_sup_1
    FROM FAMLSR16A
    WHERE FAMLSR16A.learn_sup_1a is not null
    UNION SELECT DISTINCT FAMLSR16A.student_id, FAMLSR16A.Student, FAMLSR16A.Expr1 AS learn_sup_1
    FROM FAMLSR16A


    WHERE FAMLSR16A.Expr1 is not null;]

    Thank you

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are ALL the fields being duplicated, or just the Student_id and Student fields?
    If just those two, then those records are not true duplicates. A true duplicate means ALL the fields are the same as another record.

  3. #3
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Hi
    Yes, it is just those two fields, I have a screen shot below

    Student ID Student learn_sup_1 learn_sup_2
    SJ125862 Sophie Jones 56
    SJ125862 Sophie Jones 56 59

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    So, based on your example, what do you want (expect) to see?

  5. #5
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    I only want to see
    SJ125862 Sophie Jones 56 59

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am guessing that of those two original records, one is coming from the first query, and one from the second?
    Perhaps you can do an Aggregate Query, and take the Max value of each of the last two fields.
    You might need to do it in a second, separate query based on your first one (or nest the queries, if you know how).

  7. #7
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    This is your original SQL statement:

    SELECT DISTINCT FAMLSR16A.student_id, FAMLSR16A.Student, FAMLSR16A.learn_sup_1a AS learn_sup_1
    FROM FAMLSR16A
    WHERE FAMLSR16A.learn_sup_1a is not null
    UNION SELECT DISTINCT FAMLSR16A.student_id, FAMLSR16A.Student, FAMLSR16A.Expr1 AS learn_sup_1
    FROM FAMLSR16A
    WHERE FAMLSR16A.Expr1 is not null;

    But your output show an extra column "learn_sup_2".

    So, if you change your SQL to exclude rows when "learn_sup_2" is null. Then you will get your result. Base on your current input.

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

Similar Threads

  1. Replies: 6
    Last Post: 03-29-2013, 11:05 AM
  2. Union Query Duplicates data
    By Ray67 in forum Queries
    Replies: 2
    Last Post: 10-19-2012, 07:12 AM
  3. not showing duplicates
    By YStein142 in forum Reports
    Replies: 1
    Last Post: 06-28-2012, 05:52 PM
  4. Showing Duplicates in table
    By ericfatherree in forum Access
    Replies: 3
    Last Post: 02-06-2012, 07:58 AM
  5. Showing zero values in a Union Query
    By coach32 in forum Queries
    Replies: 5
    Last Post: 09-06-2011, 07:46 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