When lookup fields are created, Sharepoint stores them
ID; # value format in related list.
For e.g.
In list "contacts" there is column called "country ".
There is item in contact with value "India" assigned in country, having item id = 10.
Now for another list "list2" when column "country" is stored as lookup column named "refcountry"; and for certain data item "India" is selected from combo box, sharePoint stores it in,
10; # India in "List 2"-> "refcountry" column.
When having caml query in list2
The typical query looks like
<Query>
<Where>
<EQ>
<Fieldref name = "refcountry"/>
<Value type = "lookup"> India </value>
</EQ>
</Where>
</Query>
The disadvantage of this way is if list contacts is having more than one entry (item or row) having value India for countryIt will return the only first one.This may give inconsistent data for further.
To avoid this query shocould be base on id not by value.
This can be achieved thru:
<Query>
<Where>
<EQ>
<Fieldref name = "refcountry" lookupid = "true"/>
<Fieldref name = "refcountry" lookupid = "true"/>
<Value type = "lookup"> 10 </value>
</EQ>
</Where>
</Query>
Where 10 is the ID for item having Country = "India"
Come from: http://abstractspaces.wordpress.com/2008/05/05/caml-query-lookup-field-by-id-not-by-value/