Results 1 to 4 of 4
  1. #1
    dmenger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    3

    Query with Counter from multiple tables

    Hi, All
    New to SQL so I clueless on how to perform simple loop query
    Here is my problem.

    I have three tables StNum, OpDs,WiNum.


    StNum is the parent table with 1 to infinite relationships to the other two tables.

    All Tables have columns such as
    StId,StNum,OpNum1,OpNum2,OpNum3, Etc.
    OpId,StNum,OpDs1,OpDs2,OpDs3, Etc.
    WiId,StNum,WiNum1,WiNum2,WiNum3, Etc.

    What I want is a query that will query the three tables to produce a record for each column listed by number. For example

    Query STNum = 1 ( From Combox Box in a Form labeled "QST")
    Produce a table with records
    OpNum1,OpDs1,WiNum1
    OpNum2,OpDs2,WiNum2
    OpNum3,OpDs3,WiNum3

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    The real issue here is a non-normalized data structure. The output you want is a normalized structure.

    A UNION query can rearrange the data. There is no wizard for UNION query, must type or copy/paste into SQL View of query builder.

    SELECT 1 AS LinkID, StNum, StId, "Num1" AS Category, OpNum1 AS Data FROM StNum
    UNION SELECT 2, StNum, StId, "Num2", OpNum2 FROM StNum
    UNION SELECT 3, StNum, StId, "Num3", OpNum3 FROM StNum;

    Do similar UNION queries for the other 2 tables.

    Then do a 4th query that joins all 3 UNION queries on the LinkID fields. Apply the combobox filter criteria to this query.
    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
    dmenger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    3
    Well the reason for the non normal structure is that if I had the normalized structure I would require more than the amount of fields allowable. I'm open to other suggestions this is just the way I figured was best to get around the field limit.



    Quote Originally Posted by June7 View Post
    The real issue here is a non-normalized data structure. The output you want is a normalized structure.

    A UNION query can rearrange the data. There is no wizard for UNION query, must type or copy/paste into SQL View of query builder.

    SELECT 1 AS LinkID, StNum, StId, "Num1" AS Category, OpNum1 AS Data FROM StNum
    UNION SELECT 2, StNum, StId, "Num2", OpNum2 FROM StNum
    UNION SELECT 3, StNum, StId, "Num3", OpNum3 FROM StNum;

    Do similar UNION queries for the other 2 tables.

    Then do a 4th query that joins all 3 UNION queries on the LinkID fields. Apply the combobox filter criteria to this query.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    I have never known a normalized structure to utilize the limit of allowable fields for a table/query.

    One indication of a non-normalized structure is multiple like-name fields, which is what I see with your example.
    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.

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

Similar Threads

  1. Query: Add 'Subset' counter to records
    By JangLang in forum Access
    Replies: 1
    Last Post: 09-20-2013, 10:51 AM
  2. Replies: 1
    Last Post: 04-12-2013, 03:03 PM
  3. Counter Query for Maintenance
    By theperson in forum Queries
    Replies: 3
    Last Post: 10-23-2012, 05:17 PM
  4. Replies: 3
    Last Post: 01-05-2012, 12:04 PM
  5. Incrementing Counter in Query
    By Rawb in forum Queries
    Replies: 9
    Last Post: 02-10-2011, 02:58 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