Results 1 to 7 of 7
  1. #1
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419

    One table unique, another duplicate - JOIN - result duplicated

    I have table a with unique x and table b with duplicated y.



    I INNER JOIN the two table and the result is also duplicated of what is in table b.
    Instead of having it duplicated (table B show twice). Can it show once and the second value as NULL or blank.

    How can I write an SQL statement to do this. Below is my simple SQL statement



    Code:
    SELECT *
    FROM a INNER JOIN b ON a.[x]=b.[y];

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why are there duplicate y? Are there other fields in both tables? Try:

    SELECT DISTINCT x, y FROM a INNER JOIN b ON a.x = b.y;

    Post example raw data and desired output if you need more assistance.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    it's a long story and a complicated scenario. I'll try to explain it as best as I could.

    I have table A with one unique field only.
    I have table B with also one unique field1 - and a bunch of other fields, field2, 3, 4, 5, 6, etc all the way to 10)

    I did two queries - with a join on field1 from table A and table B and did union all to these two queries. The result is one query go on top of the other one.
    One query is to take field2, and the other query is to take field3 and did so consecutively to all the fields.
    Because I did union all, it duplicated the ID field. so now I have two same id, one id represent field2 from one query and another id represent field3 from second query.

    I then did a join to a third table (table C). In this join I only wanted what is matched to table C.
    However because of the duplicated ID from union all, now I have repeated data from table C.
    How do I query to only show one value and the second duplicated value as a NULL or blank.

    It gets more complicated than this - when I did union all to both query in the join between table A and table B -
    some of the field in there I only wanted to show a particular field and not consecutive fields, however these fields are also duplicated with the same id.
    I didn't want to explain it on top is because it gets harder to explain it (don't want confusion). I also wanted from result with no dups but just one showing
    and the other one as blank or NULL.

    I don't know if this can be done.

    Hope is clear, if not I will revise.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Nope, not clear. Provide data.

    If you want to attach db, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    Sorry for the delay.

    Attached is the db and the sample image.
    Besides shifting the fields around, this is the scenario.
    How can I get field, for example 14, 15 and so on, the second line of the repeated field1 (id) which is also the second query of the union all query to be blank ?

    Field14 have 33 repeated twice, one on top and one again on the bottom.
    The bottom one to be blank.
    Click image for larger version. 

Name:	sample2 IMG.PNG 
Views:	14 
Size:	13.2 KB 
ID:	30174
    Attached Files Attached Files
    Last edited by johnseito; 09-01-2017 at 08:35 AM. Reason: ,.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This can only be done by creating a report - there is a property on text boxes to Hide Duplicates. Otherwise you can create a temporary table and populate it thru some sort of VBA function which checks for duplicates.

  7. #7
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    Ok, thanks for your advice.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-21-2017, 05:40 PM
  2. Replies: 1
    Last Post: 03-17-2017, 04:19 AM
  3. Join table - duplicate records
    By Lukael in forum Programming
    Replies: 10
    Last Post: 05-26-2016, 02:11 AM
  4. Replies: 2
    Last Post: 11-08-2015, 03:44 PM
  5. Replies: 1
    Last Post: 03-04-2013, 08:09 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