Joins Element (View)

Applies to: SharePoint Foundation 2010

Contains Join elements needed for a query.

<Joins>  <Join ... >  </Join>    <Join ... >  </Join>  ...</Joins>

Attributes

Attribute

Description

None

N/A

Child Elements

Join

Parent Elements

View

Note

When a Joins element is used as part of a dynamic query instead of as part of the definition of a list view; that is, when it is the value of the SPQuery.Joinsproperty rather than the Joinsproperty, then it does not really have a parent element.

Occurrences

Minimum: 0

Maximum: 1

Example

The following is an example of a Joins element with two left outer joins. CustomerName is a lookup field on an Orders list. It looks up to the ID field of a Customers list. The Customer list, in turn, has a CityName field that is a lookup field to a Cities list. The first Join element assigns ‘customers’ as an alias for the Customers list. The Eq element child defines the join using the same source and target fields that constitute the lookup relation. The second Join element assigns ‘customerCities’ as an alias to the Cities list. It defines the join in parallel to the existing lookup relation between the Customer and Cities lists.

Aliases are needed for the lists because there can be more than one join to the same list and different aliases are needed to differentiate the joins. For example, in addition to the joins from Orders to Customer and from Customer to Cities, there could also be joins from Orders to Suppliers and from Suppliers to Cities. In the case of the last join, a different alias, say ‘supplierCities’, would be assigned to the Cities list from the one that is used for the Customer to Cities join.

<Joins>
  <Join Type=’LEFT’ ListAlias=’customers’>
    <Eq>
      <FieldRef Name=’CustomerName’ RefType=’Id’ />
      <FieldRef List=’customers’ Name=’ID’ />
    </Eq>
  </Join>

  <Join Type=’LEFT’ ListAlias=’customerCities’>
    <Eq>
      <FieldRef List=’customer’ Name=’CityName’ RefType=’Id’ />
      <FieldRef List=’customerCities’ Name=’ID’ />
    </Eq>
  </Join>
</Joins>