Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:43+00:00 2026-06-17T09:46:43+00:00

Background (ie what the heck is a relative complement?) Relative Complement What I’m trying

  • 0

Background (ie what the heck is a relative complement?)

Relative Complement

What I’m trying to do

Let’s say I’ve got a custom Vehicle entity that has a VehicleType option set that is either “Car”, or “Truck”. There is a 1 to many relationship between Contact and Vehicle (ie. ContactId is on the vehicle entity). How do I write an XRM query (Linq To CRM, QueryExpression, fetch Xml, whatever) that returns the contacts with only cars?

Relative Complement Venn Diagram

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:46:45+00:00Added an answer on June 17, 2026 at 9:46 am

    In order to order to perform a true Relative Complement Query you need to be able to perform a subquery.

    Your query would basically say give me all the contacts with cars, and then, within those results, remove any contacts that have a vehicle that isn’t a car. This is what the SQL in @JasonKoopmans answer does. Unfortunetly, CRM does not support SubQueries.

    Therefore, the only way to achieve this is to either perform the sub query on the client side, as I resorted to doing, or storing the results of what would be the subquery in a manner that can be accessed through the main query (ie storing counts on the contact entity).

    You could theoretically do this “on the fly” by making a SubQueryResult entity that stores a ContactId, and SubQueryId. You’d first pull back the contacts that have at least 1 car, and create a SubQueryResult record for each record, with it’s contactId, and a single SubQueryId that is generated client side to tie them all together.

    Then you’d do another query that says give me all the contacts that are in this SubQueryResult with this SubQueryId, that do not have any vehicles that aren’t cars.

    I could only assume that this wouldn’t be any more efficient than performing the two separate queries and performing the filter client side. Although with the new ExecuteMultipleRequests in the new CRM release, it may be close.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a rails 3 app that has a model named A with
Background I am trying to build a Java program that make use of an
Background I've got an NSOutlineView that shows TrainingGroup entities. Each TrainingGroup represents a folder
Background: We're building an application that allows our customers to supply data in a
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background: I would like to dismiss a modalView that I have presented earlier and
Background My project is urgent and requires that I iterate a large XML file
Background: I've wrote a small library that is able to create asp.net controls from
I'm trying to make a strobe light for the heck of it in javascript
Background to question: We are building an online web application that requires the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.