You need to sign in to do that
Don't have an account?

semi-join question
I've been very interested in the new semi-join feature because I was sure it would solve a problem I've been having. But now I'm not so sure. From the documentation, here's a simple semi-join:
select Id, Name from Account where Id in (select AccountId from Opportunity where StageName = 'Closed Lost')
How is that any more helpful than this query? Both return exactly the same thing:
select Account.Id, Account.Name from Opportunity where StageName = 'Closed Lost'
Here's an example of what I really need to accomplish, and so far I'm not able to get this query to work. This would pull a list of all Contacts on Accounts with a lost Opportunity. It fails telling me "Cannot use a foreign key for outer field for semi join"
select Id from Contact where AccountId in (select AccountId from Opportunity where StageName = 'Closed Lost')
Is this kind of query possible? Or is there another way to get it done?
Mark
select Id, Name from Account where Id in (select AccountId from Opportunity where StageName = 'Closed Lost')
How is that any more helpful than this query? Both return exactly the same thing:
select Account.Id, Account.Name from Opportunity where StageName = 'Closed Lost'
Here's an example of what I really need to accomplish, and so far I'm not able to get this query to work. This would pull a list of all Contacts on Accounts with a lost Opportunity. It fails telling me "Cannot use a foreign key for outer field for semi join"
select Id from Contact where AccountId in (select AccountId from Opportunity where StageName = 'Closed Lost')
Is this kind of query possible? Or is there another way to get it done?
Mark
select Id, (select Id from Contacts) from Account where Id in (select AccountId from Opportunity where StageName = 'Closed Lost')
Mark
For your last question, remember that you can still use SOQL-R, so you can do
select Id, (select id, name from contacts) from Account where Id in (select AccountId from Opportunity where StageName = 'Closed Lost')
Mark