Results 1 to 2 of 2
  1. #1
    pinecrest515 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    31

    Help!!! Urgent Access SQL Query Question

    Dear Forumers,

    I need help on an Access SQL statment:

    Suppose I have the following table:

    First_Name Last_Name Age_Group Vaccinated
    John Smith Adult Yes
    Joe Smith Child No
    Mary Smith Child No
    Sam Walton Adult Yes
    Thomas Walton Child Yes
    John Walton Child Yes
    Casey James Adult Yes
    Mary Scott Adult No
    Andrew Johnson Adult Yes
    Bryon Johnson Child Yes


    I am trying to query for a list of all Adults whose children (who have same last name) have been Vaccinated.

    Ideally, the query should output the following:
    First_Name Last_Name Age_Group Vaccinated
    Sam Walton Adult Yes
    Andrew Johnson Adult Yes

    How should I best construct this query?

    I only want the Parent, Adult records, not child records.

    Something like

    Select Distinct * From Table
    Where Age_Group = ‘Adult’ AND has one or more Child with same ‘Last_Name’ AND each child is vaccinated




    Right now, I am thinking along these lines:

    Select Distinct * From t1.Last_Name, t2.Last_Name, t1.Age_Group, t1.Vaccinated
    FROM
    (table1 t1
    JOIN
    table1 t2)
    ON
    t1.Last_Name = t2.Last_Name
    Where
    t2.Vaccinated = ‘Yes’

    Based on syntax above, getting an error on Access saying there is a syntax error around FROM clause, can you, based on your extensive SQL experience, shed light into my error?

    Thanks!

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    query 1: find all last name with no vaccinated:
    select distinct last_name from table1 where vaccinated="NO"

    2 find the adult with last name not in query 1

    select a.* from table1 as a left join (
    select distinct last_name from table1 where vaccinated="NO"
    ) as b on a.last_name=b.last_name where a.age_group="Adult" and b.last_name is null

    you don't need to save query 1, it is only for helping you to understand the logic.
    save query 2 and run it.

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

Similar Threads

  1. Replies: 3
    Last Post: 11-08-2010, 11:09 AM
  2. Making A Query Criteria Urgent Help
    By jarrydred in forum Queries
    Replies: 2
    Last Post: 06-03-2010, 12:59 AM
  3. Replies: 0
    Last Post: 11-10-2009, 12:06 PM
  4. Query to run from a FORM VERY URGENT
    By prag in forum Forms
    Replies: 14
    Last Post: 10-08-2009, 01:51 PM
  5. Basic question, urgent help needed.
    By fishnu in forum Access
    Replies: 12
    Last Post: 03-18-2009, 01:39 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