Results 1 to 2 of 2
  1. #1
    fuecheefang is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    43

    SQL query to retrieve multiple items from a single column HELP.

    I need some suggestions:



    What is the most efficient sql code to use, I have a column with Site location Mac codes about 3000 different items, and our department supportsabout 400 of these sites. What is the best query to use and can you all help supply an example?

    SELECTMAC CodesFROMmy_tableWHEREMAC Codes IN('Value1','Value2',...);



    Thanks.

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Obviously putting 400 codes in a value list is a non-starter - it might work (it would be an awfully long string), but maintaining it would be a nightmare.

    Is there any field in my_table that identifies which department supports that site? If so, could you use that in the Select statement?


    For example:

    SELECT [
    MAC Codes] FROM my_table WHERE Supporting_Department_ID = " & your_department_ID

    If not, then do you have a table somewhere that lists the sites your department supports? If so, then you could have a SQL Select like this (call that table Site_List):

    SELECT [MAC Codes] FROM my_table WHERE [Mac Code] in (Select [Mac Codes] from Site_List)

    If you don't currently have such a table, creating one wouldn't be very difficult. You'd have to enter the list by hand I guess, but after that, maintenance is easy.



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

Similar Threads

  1. Replies: 4
    Last Post: 08-19-2015, 08:32 PM
  2. Replies: 1
    Last Post: 09-11-2014, 05:53 AM
  3. Replies: 75
    Last Post: 06-03-2014, 09:49 AM
  4. Replies: 1
    Last Post: 09-01-2013, 09:46 PM
  5. Replies: 5
    Last Post: 12-01-2011, 05:38 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