Results 1 to 5 of 5
  1. #1
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169

    Query on criteria from two tables

    Hi,



    I have two tables where one table is a list of questions (Table1) and the other table is a list of responses (Table2) that are related to the questions. The related field is QuestionID and is a one to many relationship. These questions and responses will be displayed as a survey of sorts and only certain questions should be displayed and certain responses should be displayed based on certain criteria. See the attached file that shows the table structure with some fake data and the desired query results based on the criteria being "like red" or "is null". I don't know how to show the tables clearly in this question so I am resorting to the Word attachment. This is the code I am starting with but I can't figure out how to apply the criteria to the ResponseCriteria to filter out the response without affecting the QuestionCriteria.

    Code:
    SELECT Table1.QuestionID, Table1.QuestionText, Table1.QuestionCriteria, Table2.ResponseText, Table2.ResponseCriteria
    FROM Table1 INNER JOIN Table2 ON Table1.QuestionID = Table2.QuestionID
    WHERE (((Table1.QuestionCriteria) Like "*red*" Or (Table1.QuestionCriteria) Is Null));
    Last edited by jpkeller55; 09-06-2010 at 02:25 PM. Reason: wrong attachment

  2. #2
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Answered my own question believe it or not! Simple matter of adding the word And plus the additional criteria! Woo Hoo!
    Code:
    SELECT Table1.QuestionID, Table1.QuestionText, Table1.QuestionCriteria, Table2.ResponseText, Table2.ResponseCriteria
    FROM Table1 INNER JOIN Table2 ON Table1.QuestionID = Table2.QuestionID
    WHERE (((Table1.QuestionCriteria) Like "*red*" Or (Table1.QuestionCriteria) Is Null)) and
    (((Table2.ResponseCriteria) Like "*red*" or (Table2.ResponseCriteria)Is Null));

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So...I would guess this thread is ready for you to follow the link in my sig and mark as Solved.

  4. #4
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Thanks for the reminder...in my excitement I forgot to mark as solved.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thank you.

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

Similar Threads

  1. Query Criteria
    By combine21 in forum Queries
    Replies: 12
    Last Post: 09-08-2010, 01:06 PM
  2. Query Criteria
    By MrMitch in forum Queries
    Replies: 0
    Last Post: 03-31-2009, 02:25 PM
  3. Query Criteria
    By jena in forum Access
    Replies: 1
    Last Post: 08-03-2008, 04:08 AM
  4. Query Criteria
    By jena in forum Queries
    Replies: 1
    Last Post: 04-29-2008, 11:00 AM
  5. Need help with tables and query criteria
    By DevintheDude in forum Access
    Replies: 0
    Last Post: 09-12-2007, 08:41 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