Results 1 to 3 of 3
  1. #1
    jscriptor09 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    60

    Query question

    Hi

    I have a situation where the data looks as follows:

    store1 item1
    store1 item2
    store1 item3

    store2 item1
    store2 item3
    store2 item4
    store2 item5

    store3 item2
    store3 item3
    store3 item4
    store3 item6

    store4 item1


    store4 item8
    store4 item7
    store4 item9

    I need to write a SQL that:
    look for the store that carries item 2 and return all items in the stores found. In this example, the return values should be

    store1 item1
    store1 item2
    store1 item3

    store3 item2
    store3 item3
    store3 item4
    store3 item6

    Note that all items in stores 1 and 3 are returned; not just the 2 rows where Item 2 was found.

    I appreciate any help constructing the SQL for this

    Thanks
    Mike

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    A couple of ways

    There's lots of ways, but something like this would work:
    Code:
    SELECT T1.StoreName, T1.ItemName
    FROM MyTable AS T1
    WHERE T1.StoreName IN 
    (SELECT T2.StoreName 
    FROM MyTable AS T2
    WHERE T2.ItemName = "Item 2");
    or this:
    Code:
    SELECT T1.StoreName, T1.ItemName
    FROM MyTable AS T1, MyTable AS T2
    WHERE ((T1.StoreName = T2.StoreName)
    AND (T2.ItemName = "Item 2"))
    GROUP BY T1.StoreName, T1.ItemName;

  3. #3
    jscriptor09 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    60
    Hi Dal

    Thanks a lot. This works.

    Mike

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

Similar Threads

  1. Query question/help
    By 9944pdx in forum Queries
    Replies: 4
    Last Post: 12-12-2017, 08:13 PM
  2. vba query question
    By jscriptor09 in forum Programming
    Replies: 2
    Last Post: 10-08-2011, 07:22 PM
  3. Query Question
    By CarlV in forum Access
    Replies: 2
    Last Post: 09-20-2011, 06:25 AM
  4. Query question
    By j2curtis64 in forum Queries
    Replies: 8
    Last Post: 07-29-2011, 01:45 PM
  5. Query Question
    By Guiseppe in forum Queries
    Replies: 5
    Last Post: 03-23-2010, 04:32 PM

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