【问题标题】:Salesforce SOQL statementSalesforce SOQL 语句
【发布时间】:2014-03-20 15:59:23
【问题描述】:

我正在使用 Salesforce 并尝试编写 SOQL 语句。我的表格如下所示:

人物:[id, name]

相关:[id, personid1, personid2]

在 sql 中,要查找与某人相关的所有人,我可能会这样写:

select person2.name from 
person person1, related, person person2 
where person1.id = 'xyz'
and person1.id = related.personid1 
and related.person2 = person2.id

如何使用 SOQL 语句获得相同的结果集?

【问题讨论】:

    标签: salesforce soql


    【解决方案1】:

    出于此查询的目的,我将假设您的自定义对象和字段使用常规 Salesforce 命名约定。

    如果您使用记录 ID 进行查询:

    select personid2__r.Name from Related__c where personid1__c = 'xxxyyyzzz123123'
    

    或者,如果您使用名称进行查询:

    select personid2__r.Name from Related__c where personid1__r.Name = 'John Doe'
    

    如果您绝对需要返回 Person__c 类型的记录,那么您可以执行以下操作:

    select Id, Name from Person__c where Id in (select personid2__c from Related__c where personid1__c = 'xxxyyyzzz123123')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多