Results 1 to 4 of 4
  1. #1
    ahunter488 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    2

    Querying id by having criteria in two lines


    Need help creating a query to display id's where users have both L & R (bilateral).

  2. #2
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    This should work for you:

    SELECT TabR.Field1
    FROM (
    SELECT sampledata.Field1
    FROM sampledata
    WHERE sampledata.Field2="R") AS TabR
    INNER JOIN sampledata ON TabR.Field1 = sampledata.Field1
    WHERE sampledata.Field2="L";

  3. #3
    ahunter488 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    2
    When I use this in my actual database,
    I receive multiple listings when
    listed items
    are
    R
    L
    R
    or
    L
    R
    L
    Also, I get one bad result at the first entry for one
    L
    L
    L
    The rest of inquiry appears to be working correctly, however if I can prevent the incorrect entry I would be more certain that this is pulling the correct results.
    Anything I can do to prevent this (and thank you very much for the help)

    Also, if I wanted to get the opposite data, users that do not have and L & R only L or R (or multiples of the same), how could this be acheived? Is there a subtraction query that would remove the results of this query from the original query?

    SELECT TabR.QueryBilateralImplant.PatientId
    FROM [SELECT QueryBilateralImplant.PatientId
    FROM QueryBilateralImplant
    WHERE QueryBilateralImplant.AudSide="R"]. AS TabR
    INNER JOIN QueryBilateralImplant ON TabR.PatientId = QueryBilateralImplant.PatientId
    WHERE QueryBilateralImplant.AudSide="L"
    ORDER BY QueryBilateralImplant.PatientId;

    Quote Originally Posted by Rod View Post
    This should work for you:

    SELECT TabR.Field1
    FROM (
    SELECT sampledata.Field1
    FROM sampledata
    WHERE sampledata.Field2="R") AS TabR
    INNER JOIN sampledata ON TabR.Field1 = sampledata.Field1
    WHERE sampledata.Field2="L";

  4. #4
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Bit pushed for time right now but off the top of my head you need to use the DISTINCT predicate to avoid duplicates in the result set.

    SELECT DISTINCT TabR.QueryBilateralImplant.PatientId
    FROM [SELECT DISTINCT QueryBilateralImplant.PatientId
    FROM QueryBilateralImplant
    WHERE QueryBilateralImplant.AudSide="R"]. AS TabR
    INNER JOIN QueryBilateralImplant ON TabR.PatientId = QueryBilateralImplant.PatientId
    WHERE QueryBilateralImplant.AudSide="L"
    ORDER BY QueryBilateralImplant.PatientId;

    I haven't tested this!

    Can't think why you get your bad result.

    Post back if it still doesn't work.

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

Similar Threads

  1. Creating a String in VBA over multiple lines
    By Mazdaspeed6 in forum Programming
    Replies: 13
    Last Post: 01-03-2011, 12:32 PM
  2. line chart not showing lines
    By ajetrumpet in forum Reports
    Replies: 0
    Last Post: 09-11-2010, 05:55 PM
  3. Creating Multiple Lines per Member
    By SecretGeek in forum Access
    Replies: 2
    Last Post: 08-20-2010, 06:19 AM
  4. GROUP numerous lines to one record
    By tweetyksc in forum Queries
    Replies: 3
    Last Post: 07-21-2010, 01:14 PM
  5. Duplicating lines in an invoice report
    By GordonEdinburgh in forum Forms
    Replies: 0
    Last Post: 04-21-2007, 12:20 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