Results 1 to 4 of 4
  1. #1
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17

    Select query

    I have a database with 2 tables


    SAP_Data
    Old_MM WI_1 WI_2 ..... WI_15
    12345 1 2
    23456 1 10
    34567 2 3
    WI
    ID WI
    1 Clean
    2 take to lab
    3 Filter
    .
    .
    .
    What I need to do is make a query that selects the WI based on the number in WI_1, WI_2... and have it be in the right order.
    I've come up with a select & union query

    SELECT SAP_Data.Old_MM, WI.WI
    FROM WI, SAP_Data
    WHERE (((WI.ID)=[SAP_Data].[WI_1]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_2]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_3]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_4]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_5]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_6]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_7]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_8]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_9]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_10]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_11]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_12]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_13]))
    UNION ALL Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_14]))
    UNION Select SAP_Data.Old_MM, WI.WI
    From WI, SAP_Data
    Where (((WI.ID)=[SAP_Data].[WI_15]));

    This does work but I can't for the life of me get it in the correct order. It all comes out seemingly random.
    I've tried doing them all in separate queries but when I add them together it won't show the ones that are null.

    If there is a better way to do this please let me know. I'm new to access and know very little SQL or VBA. I tried to upload the database but it's way too big.
    Thanks, Sarah

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    The table should have been designed as
    [Old_MM], [WI]

    This way the queries would work in all fields at once.

    Have you tried importing the data into its own linked table? That way its separated from the main program, and will only contain that 1 table.
    Ive done this and it held 15 million records.
    Or is your data still too large for this?

  3. #3
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    I see what you're saying about the design but I didn't design it that way so that it would be easier for the end user to edit (I have some pretty Access-phobic people using it). This way when they look at the table all of the info is in one line instead of multiple.
    I'm not worried about the database being too big in the end. I just can't upload it here because it's 2560 KB and this website only supports up to 500 KB.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I see what you're saying about the design but I didn't design it that way so that it would be easier for the end user to edit (I have some pretty Access-phobic people using it). This way when they look at the table all of the info is in one line instead of multiple.
    Your design violates the rules of normalization (see: http://sbuweb.tcu.edu/bjones/20263/A...sDB_Design.pdf). When you do that in a relational database setting, it can make very simple task into very complex ones (as you are discovering). I know, because I have been there myself!

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

Similar Threads

  1. Replies: 5
    Last Post: 05-14-2014, 01:17 PM
  2. Replies: 1
    Last Post: 05-02-2014, 09:29 AM
  3. Replies: 5
    Last Post: 05-01-2013, 11:39 AM
  4. Replies: 7
    Last Post: 05-02-2012, 08:04 AM
  5. Replies: 2
    Last Post: 01-31-2011, 08:31 AM

Tags for this Thread

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