Results 1 to 6 of 6
  1. #1
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

    Finding Unmatched Records from Denormalized Database

    I am working with an ancient software package that is not very well designed (not even close to being normalized). All the data is held in DBF files.
    I need to recreate some reporting that we have using Access. The reporting is a bit complex, so I am trying to make it as efficient as possible, so as not to bog down the process too much.

    Here is the current situation.
    There is a table that lists a Company ID and then twenty different possible "plan" fields (let's call it Table1).
    There is another table that lists all the "plans" that the company actually has (let's call that Table2).
    I need to find all the Codes in Table 2 that do not appear in Table 1.

    Here is an example of Table1 (header row and one data record):


    Code:
    CO ID	PR1	PR2	PR3	PR4	PR5	PR6	PR7	PR8	PR9	PR10	PT1	PT2	PT3	PT4	PT5	PT6	PT7	PT8	PT9	PT10
    ABC123	AB	AD	AZ	DX	DZ	RM					NS	NZ	FB	FD
    Here is an example of Table2 (header row and 13 data records):
    Code:
    CODES
    AB
    AC
    AD
    AZ
    DX
    DZ
    FB
    FC
    FD
    NS
    NZ
    RM
    RN
    So, in my query, I should return three records, AC, FC, and RN.

    If the Table1 was normalized, this would be very easy (an Unmatched Query). Now, I could use record sets and VBA and loop through Table1 to create a new temporary table (which is normalized), and use that in an Unmatched Query. But I was wondering (and hoping) if there is a more efficient way to simply use dynamic queries without any need for temporary tables.

    Any ideas?

  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,521
    My first thought is a UNION query on table 1 to "normalize" it, then the unmatched query comparing that to table 2..
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    My first thought is a UNION query on table 1 to "normalize" it, then the unmatched query comparing that to table 2.
    Do you mean have a query with 19 UNION statements in it?
    Or is there a simpler way?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think one way or the other you want to normalize that data. You can either "use record sets and VBA and loop through Table1 to create a new temporary table (which is normalized)", or create a UNION query that yes, would have a SELECT clause for each of the "PR" fields in the table. Either way it's a bit of work, which is not unexpected when you have to work around a non-normalized design. I think the difference is that the UNION query is more of a one-time setup. If you create a temporary table, you would need to rerun the process as the data changes. The UNION query is a dynamic re-representation of the data. In other words, as the data in table 1 changes, the UNION query automatically reflects the changes (presuming no new fields of course).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Thanks Paul. Just wanted to make sure I wasn't overlooking a simpler option. I couldn't think of one myself, but sometimes I "can't see the forest for the trees".

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You may be overlooking one, but if so we both are. There are a lot of trees around here though.
    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. Help? One Table, Finding Unmatched
    By geofftke in forum Access
    Replies: 1
    Last Post: 06-07-2013, 11:20 PM
  2. Query and unmatched records
    By jlgray0127 in forum Forms
    Replies: 1
    Last Post: 03-19-2012, 05:56 PM
  3. Help! Unmatched Records Query
    By Hberg in forum Access
    Replies: 1
    Last Post: 03-09-2012, 03:41 PM
  4. Replies: 1
    Last Post: 12-08-2011, 01:52 PM
  5. finding records in a database....
    By softspoken in forum Forms
    Replies: 1
    Last Post: 04-23-2010, 11:17 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