Results 1 to 13 of 13
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    You have written a subquery that can return more than one field without using EXISTS reserved word

    I'm getting this error.



    any ideas where goes wrong?
    Thanks in advance


    Code:
    SELECT DuplicatesUnionQ.PATIENT_ID, DuplicatesUnionQ.PATIENT_NAME, DuplicatesUnionQ.GENDER, DuplicatesUnionQ.DOB, DuplicatesUnionQ.C_SOURCE, DuplicatesUnionQ.CATEGORY_TYPE
    FROM DuplicatesUnionQ
    WHERE ((DuplicatesUnionQ.PATIENT_ID) IN (SELECT [DuplicatesUnionQ.PATIENT_ID], [DuplicatesUnionQ.PATIENT_NAME] FROM [DuplicatesUnionQ] As Tmp 
    GROUP BY DuplicatesUnionQ.PATIENT_ID, DuplicatesUnionQ.PATIENT_NAME
    HAVING count(DuplicatesUnionQ.PATIENT_ID) <2 ))
    order by DuplicatesUnionQ.PATIENT_ID, DuplicatesUnionQ.PATIENT_NAME, DuplicatesUnionQ.GENDER, DuplicatesUnionQ.DOB, DuplicatesUnionQ.C_SOURCE, DuplicatesUnionQ.CATEGORY_TYPE;

  2. #2
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    I'm not a master at doing this kind of thing, so take my suggest or not.
    On your WHERE you are matching the ID from DuplicatesUnionQ to the ID returned from a different query. Why are you returning the Patient_name in the inner query?
    This seems to be what the error is saying also.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Agree with James - PATIENT_NAME Is not needed in the inner query at all and is causing the error. Remove all references to PATIENT_NAME from the inner query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by June7 View Post
    Agree with James - PATIENT_NAME Is not needed in the inner query at all and is causing the error. Remove all references to PATIENT_NAME from the inner query.
    I have this table : DuplicatesUnionQ which consists of Duplicates.

    Actually, I wanna retrieve the person data ( id , name , gender , dob , source , category_type)
    Where names is not match .

  6. #6
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by orange View Post
    In addition to James' comment, What exactly are you trying to do in plain English?
    I have this table : DuplicatesUnionQ which consists of Duplicates.

    Actually, I wanna retrieve the person data ( id , name , gender , dob , source , category_type)
    Where names is not match .

  7. #7
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Current Code: Only display Patient name and ID
    Where names is not the same.

    Example :
    ID | Name
    123 | Teddy
    123 | Ted

    Code:
    SELECT DuplicatesUnionQ.PATIENT_ID, DuplicatesUnionQ.PATIENT_NAME
    FROM DuplicatesUnionQ
    GROUP BY DuplicatesUnionQ.PATIENT_ID, DuplicatesUnionQ.PATIENT_NAME
    HAVING count(DuplicatesUnionQ.PATIENT_NAME) < 2;
    However I wanna show this data
    ID | Name | Gender | DOB | Category_Type
    123 | Teddy | F | 12-2-2015 | Cross
    123 | Ted | F | 12-2-2015 | Intra

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What exactly are you trying to do?
    These are NOT duplicates,
    123 | Teddy
    123 | Ted

    What is the ID field?
    What is the PK of your table?

  9. #9
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by orange View Post
    What exactly are you trying to do?
    These are NOT duplicates,
    123 | Teddy
    123 | Ted

    What is the ID field?
    What is the PK of your table?
    Duplicate IDs. Different Name but Same ID
    I dont have a Primary Key in my table .
    ID field ? Data Type ? If its data type , its short text .


    This is the final result i wanna achieve .
    ID | Name | Gender | DOB | Category_Type
    123 | Teddy | F | 12-2-2015 | Cross
    123 | Ted | F | 12-2-2015 | Intra
    I wanna Create a filter whereby ,
    Display all those patient data with the SAME ID but Different Name .
    Eg.

    I wanna check if the Name has been updated in the "INTRA" system.
    If it is not updated , it will show this:

    ID | Name | Gender | DOB | Category_Type
    123 | Teddy | F | 12-2-2015 | Cross
    123 | Ted | F | 12-2-2015 | Intra

  10. #10
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by orange View Post
    What exactly are you trying to do?
    These are NOT duplicates,
    123 | Teddy
    123 | Ted

    What is the ID field?
    What is the PK of your table?
    Duplicate IDs. Different Name but Same ID
    I dont have a Primary Key in my table .
    ID field ? Data Type ? If its data type , its short text .


    This is the final result i wanna achieve .
    ID | Name | Gender | DOB | Category_Type
    123 | Teddy | F | 12-2-2015 | Cross
    123 | Ted | F | 12-2-2015 | Intra
    I wanna Create a filter whereby ,
    Display all those patient data with the SAME ID but Different Name .
    Eg.

    I wanna check if the Name has been updated in the "INTRA" system.
    If it is not updated , it will show this:

    ID | Name | Gender | DOB | Category_Type
    123 | Teddy | F | 12-2-2015 | Cross
    123 | Ted | F | 12-2-2015 | Intra

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Every table should have a primary key whose job is to uniquely identify each record in the table

  12. #12
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by orange View Post
    Every table should have a primary key whose job is to uniquely identify each record in the table
    So without a PK , I can't do that "filter" function?

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I gave a response earlier using tblPeeps. I'm resending but using your "num" field (not a PK)

    SELECT tblPeeps.pname, Count(tblPeeps.num) AS CountOfnum
    FROM tblPeeps
    GROUP BY tblPeeps.pname
    HAVING (((Count(tblPeeps.num))<2));

    This was using some of your sample data and found records where the NUM was not unique. That is, for a given NUM there could be different pNames.

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

Similar Threads

  1. Code to return 'No Record exists'
    By coach32 in forum Programming
    Replies: 2
    Last Post: 07-28-2015, 07:29 AM
  2. Reserved Word 'REPORT$'
    By JeffChr in forum Access
    Replies: 4
    Last Post: 02-12-2014, 06:56 AM
  3. Run-Time Error '0' Reserved Word
    By CementCarver in forum Programming
    Replies: 1
    Last Post: 10-05-2013, 09:04 AM
  4. Reserved word
    By squirrly in forum Access
    Replies: 6
    Last Post: 09-20-2011, 02:43 PM
  5. Replies: 1
    Last Post: 01-30-2010, 04:45 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