Results 1 to 5 of 5
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    avoid multiple queries

    all, using 2010. I have two tables. :



    Code:
    tblone: 
    cust_id 
    mtr_id
    state
    
    tbltwo: 
    cust_id
     state
    name
    They both have the main field; cust_id in both tables. In table one; there is a mtr_id field which is associated with cust_id field. I need to match this field in table two. So I setup a query to do this which which works fine:
    Code:
    SELECT tblone.mtr_id, tblTwo.cust_id, tblTwo.CNAME, tblTwo.EFF_DTE, tblTwo.TAX_DESC, tblTwo.STATE, tblTwo.[rate], tblTwo.[Acctnum] tblTwo.Notes
    FROM tblone LEFT JOIN tblTwo ON (tblone.State = tblTwo.STATE) AND (tblone.cust_id = tblTwo.cust_id);
    Table one is kept updated by the user. My problem is in tblone; the user mixed up the fields. What I mean is; instead of putting the cust_id in the cust_id field; they put it in the mstr_id field. So now I have some records with the mstr_id field in the cust_id field and cust_id in the mstr_id field and my query is set up by joining the cust_id There are too many records; almost 10000 to correct this. So my question is does anyone know a way I can use the above query without having to use multiple queries to accomplish what I need. I hope I didn't confuse the issue. Thanks

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    First, let me say that is a bad database design that would allow this to happen and I strongly suggest you correct it. That said, you can probably accomplish this by query(s) or else a make table and then clean up the data.

    Good Luck.

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Yes; I failed to mention this is not my database and I've been asked to help. I just thought it was a quick way out of this. Thanks anyway

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Not a problem. Feel sorry for you.

    Good Luck!

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would attempt to fix the data. I would look carefully at the data first. Determine how and when the user did this (what method did they use). If the data is not correct, it needs to be fixed. If some of the data is not correct, you can not depend on any of the records.

    After isolating the bad records, maybe using queries to isolate records that are orphaned because the JOIN is looking for a non existing PK, I would design some Update queries to populate the correct Key field with the value from mstr_id.

    If you can create a query based on bad data and you can depend on the query, you can fix the bad data. So fix the bad data.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-18-2013, 07:29 AM
  2. Multiple FIRST/LAST Queries
    By dr4ke in forum Queries
    Replies: 2
    Last Post: 07-07-2012, 09:07 AM
  3. How do I avoid multiple entries
    By schwabe in forum Queries
    Replies: 2
    Last Post: 02-01-2012, 04:16 PM
  4. Replies: 1
    Last Post: 01-10-2012, 10:12 PM
  5. Replies: 0
    Last Post: 02-27-2011, 04:21 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