Results 1 to 2 of 2
  1. #1
    tomseattle is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    1

    Display rows where column values are the same


    Hello, I am a complete newbie when it comes to access so I really don't know how to do this. I would like to take a database that has the following fields and get the results I have shown here.

    name age weight type sample_num
    tom 30 200 1 1
    tom 30 2 1
    jen 25 120 1 2
    jen 25 2 2
    mary 21 115 1 3
    beth 20 110 1 4


    Result
    name age weight Sample_num
    tom 30 200 1
    jen 25 120 2

    I want to search the sample_num and find equal numbers. There has to be both a type 1 and a type 2. Can I even do this with a query?

    Thanks for the help

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Assuming your names are unique, you could use either this -
    Code:
    SELECT T1.name, T1.age, T1.weight, T1.sample_num
    FROM MyTable as T1, MyTable as T2
    WHERE T1.Name = T2.Name
    AND T1.Type = '1' 
    AND T2.Type = '2';
    or this -
    Code:
    SELECT T1.name, T1.age, T1.weight, T1.sample_num
    FROM MyTable as T1
    WHERE T1.Type = '1' 
    AND T1.Name IN 
       (SELECT T2.Name
        FROM MyTable as T2
        WHERE T2.Type = '2' 
       );
    or this -
    Code:
    SELECT T1.name, T1.age, T1.weight, T1.sample_num
    FROM MyTable as T1 
         INNER JOIN 
         MyTable as T2
         ON T1.Name = T2.Name
    WHERE T1.Type = '1' 
    AND T2.Type = '2';
    You should take the quotes off the '1' and '2' if they're numeric types.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  2. Replies: 2
    Last Post: 12-05-2011, 04:53 AM
  3. Replies: 3
    Last Post: 09-28-2011, 04:29 PM
  4. Replies: 2
    Last Post: 08-28-2011, 06:06 AM
  5. inserting values in column based another column
    By wasim_sono in forum Database Design
    Replies: 1
    Last Post: 06-27-2006, 05:23 AM

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