0

How to create CAML query to find items which have all specified lookup values?

The query below returns items which have item1 or item2, or (item1 and item2). But I would like to return only items which have (item1 and item2)

<Where>
  <And>
     <Eq>
        <FieldRef Name='Column1' />
        <Value Type='LookupMulti'>item1</Value>
     </Eq>
     <Eq>
        <FieldRef Name='Column1' />
        <Value Type='LookupMulti'>item2</Value>
     </Eq>
  </And>
</Where>
  • Actually it is working as expected. There was an typo in CAML query. – Martin P. Jan 10 '18 at 9:00
0

Try the following caml got from CAML Designer:

 <Where>
      <And>
         <Eq>
            <FieldRef Name='lookuptest' />
            <Value Type='LookupMulti'>China</Value>
         </Eq>
         <Eq>
            <FieldRef Name='lookuptest' />
            <Value Type='LookupMulti'>USA</Value>
         </Eq>
      </And>
   </Where>

To avoid wrong type or spelling, I would highly recommend to use CAML Designer to build CAML Query: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.