Results 1 to 3 of 3
  1. #1
    losty is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    2

    Query to select 1 unique value when using Join?

    Hey guys,

    I have a somewhat complex problem that is giving me headaches. I have 2 tables (both have in excess of 1 million rows) and I want to effectively join them together. Using a small example below maybe you can help. Im starting with tables 1 and 2, and want to end up with table 3.



    Field2(table1) and Field4(table2) are the same values (identical). However, because they have 2 identical values (i.e. 1000) when i try to do a join it makes too many duplicates. I basically want in the final table for Field 1 to only be present once (no duplicates) and the first time it calls a value from Field 3 to not duplicate that value (Identical values may be present but they will have different Field4s associated with them).

    Table 2 has many more values than exist in table 1 and some need to be skipped over (i.e. the value 1002 in Table2 doesn't have a matching "L" value in Table1 and so can be ignored). An example of the results I dont want is shown in table 4 for reference purposes.

    Many thanks!

    Table 1
    Field1 Field2
    L1 1000
    L2 1000
    L3 1001
    L4 1003

    Table 2
    Field3 Field4 Field5 Primary Key
    4.5 1000 2000 1
    3.4 1000 2000 2
    2.4 1001 2001 3
    1.7 1002 2002 4
    1.4 1003 2003 5

    Table3 - The results I want
    Field1 Field2 Field3 Field5
    L1 1000 4.5 2000
    L2 1000 3.4 2000
    L3 1001 2.4 2001
    L4 1003 1.4 2003

    Table4-The results I don't want where L1 and L2 become duplicated.
    Field1 Field2 Field3 Field5
    L1 1000 4.5 2000
    L1 1000 3.4 2000
    L2 1000 4.5 2000
    L2 1000 3.4 2000
    L3 1001 2.4 2001
    L4 1003 1.4 2003

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    This article may help
    http://forums.aspfree.com/attachment...2&d=1201055452

    Each row in a table should have some field that uniquely identifies that row.
    Said differently - each row requires a unique identifier.

  3. #3
    losty is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    2
    So one way I did do this (sorry I should have mentioned) was that in table1 the unique ID is basically field 1. To generate a unique ID in Table2 I put in a Primary Key...

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

Similar Threads

  1. Left-Outer Join on Non-Unique ID
    By defaultuser909 in forum Queries
    Replies: 2
    Last Post: 09-06-2012, 10:16 AM
  2. when (select statement within inner join should be used)?
    By learning_graccess in forum Programming
    Replies: 1
    Last Post: 05-17-2012, 01:54 PM
  3. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  4. Unique query result issue
    By QueryFury in forum Access
    Replies: 1
    Last Post: 11-15-2011, 11:09 PM
  5. query that will contain all unique records
    By halcolm1 in forum Queries
    Replies: 0
    Last Post: 01-19-2007, 05:34 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