Results 1 to 5 of 5
  1. #1
    Aye is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    2

    Creating A query on an existing query. please help

    Hi,



    I am a newbie in MS Access and I have come across a challenging task (at least on my level) that anyone of you might already solved..

    Can anyone tell me how to create a Query with an existing query.
    I have attached a snapshot of the Datasheet view of an existing query wherein there are 3 fields; Parents, Child and BirthDate.
    I want to create a query that will filter all the Parents that has more than 1 Child and are not born on the same BirthDate. The result should show the same fields (Parents, Child and BirthDate) with the above condition.
    In a simple explanation, we can say that those child having the same parents and the same BirthDates are twins or triplets, there is also an Only Child and the others are Parents with more than 2 children. I want to have the list of those Parents with more than 2 children with their BirthDates.
    I have more than 12 thousand rows to work on and I want to do this using a MS Access.
    Please see the attached snapshot for your reference.

    Thanks in advance.
    Aye
    Attached Thumbnails Attached Thumbnails HSN_Query.JPG  

  2. #2
    KathyCo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    North Carolina
    Posts
    8
    Try this.

    You just attach the query just like you would a table. Then copy this into your SQL view. Change name of fields and query as needed.

    SELECT Query1.Parents, Query1.Birthdate, Query1.Child
    FROM Query1
    WHERE (((Query1.Parents) In (SELECT [Parents] FROM [Query1] As Tmp GROUP BY [Parents],[Birthdate] HAVING Count(*)=1 And [Birthdate] <> [Query1].[Birthdate])))
    ORDER BY Query1.Parents, Query1.Birthdate;

    I hope this helps!

    Thanks,

    Kathy

  3. #3
    KathyCo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    North Carolina
    Posts
    8
    The result will be different than what you had because F is actually in there 4 times instead of 3. Just wanted to note that so you would not wonder why. I assumed that the Parents field would be unique or it needs to be for what I sent to work.
    Thanks,

    Kathy

  4. #4
    Aye is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    2
    Hi Kathy,

    Indeed, you are right, there is an extra child on Parent "F" which was not included on the expected result I posted as reference.
    I tried your Code and it worked!!!

    Thanks and have a GREAT day ahead.

    Regards,
    Aye

  5. #5
    KathyCo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    North Carolina
    Posts
    8
    You are welcome. Glad I could help!

    Kind Regards,

    Kathy

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

Similar Threads

  1. Replies: 3
    Last Post: 01-15-2016, 02:35 PM
  2. Creating a great FE/BE from existing monster database
    By marinelizard in forum Database Design
    Replies: 2
    Last Post: 12-14-2015, 06:54 PM
  3. Creating database from existing data
    By arturju in forum Database Design
    Replies: 4
    Last Post: 05-15-2014, 01:29 PM
  4. Replies: 10
    Last Post: 11-19-2013, 06:09 PM
  5. creating unique ID on existing table
    By TheShabz in forum Access
    Replies: 6
    Last Post: 01-24-2011, 03:53 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