<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Complex sql in QueryParameters whereClause in Swift Maps SDK Questions</title>
    <link>https://community.esri.com/t5/swift-maps-sdk-questions/complex-sql-in-queryparameters-whereclause/m-p/1555942#M455</link>
    <description>&lt;P&gt;I have 2 layers - "poles" and "poleAssembly". I want to display a subset of the poles layer where the features have a relationship with at least one feature in the poleAssembly layer. The relationship is defined by matching the globalID in the poles layer with the poleID in the poleAssembly table.&lt;/P&gt;&lt;P&gt;Here's an example of the data:&lt;/P&gt;&lt;P&gt;poles:&lt;BR /&gt;{name: "pole1", globalID: "a"}&lt;BR /&gt;{name: "pole2", globalID: "b"}&lt;BR /&gt;{name: "pole3", globalID: "c"}&lt;/P&gt;&lt;P&gt;poleAssembly:&lt;BR /&gt;{name: "assembly1", poleID: "b"}&lt;BR /&gt;{name: "assembly2", poleID: "b"}&lt;BR /&gt;{name: "assembly3", poleID: "c"}&lt;BR /&gt;{name: "assembly4", poleID: "d"}&lt;/P&gt;&lt;P&gt;In this case, the map should display only pole2 and pole3 because their globalIDs match at least one of the poleAssembly's poleIDs.&lt;/P&gt;&lt;P&gt;I'd like to accomplish this via a SQL statement in either QueryParameter.whereClause or FeatureLayer.definitionExpression.&lt;/P&gt;&lt;P&gt;I've tried the following-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;if let polesTable = polesLayer.featureTable as? ServiceFeatureTable {
     var params = QueryParameters()
     params.whereClause = "EXISTS (SELECT 1 FROM poleAssembly WHERE 
                            poleAssembly.poleID = poles.GlobalID)"
     let results = try await polesTable.queryFeatures(using: params)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This throws error 400: "Cannot perform query. Invalid query parameters."&lt;/P&gt;&lt;P&gt;i've also tried this as whereClause "GlobalID IN (SELECT poleID FROM poleAssembly)" with same error&lt;/P&gt;&lt;P&gt;Any help or explanation on how to achieve this filter would be appreciated. Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2024 18:24:43 GMT</pubDate>
    <dc:creator>CalebMitcler</dc:creator>
    <dc:date>2024-11-06T18:24:43Z</dc:date>
    <item>
      <title>Complex sql in QueryParameters whereClause</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/complex-sql-in-queryparameters-whereclause/m-p/1555942#M455</link>
      <description>&lt;P&gt;I have 2 layers - "poles" and "poleAssembly". I want to display a subset of the poles layer where the features have a relationship with at least one feature in the poleAssembly layer. The relationship is defined by matching the globalID in the poles layer with the poleID in the poleAssembly table.&lt;/P&gt;&lt;P&gt;Here's an example of the data:&lt;/P&gt;&lt;P&gt;poles:&lt;BR /&gt;{name: "pole1", globalID: "a"}&lt;BR /&gt;{name: "pole2", globalID: "b"}&lt;BR /&gt;{name: "pole3", globalID: "c"}&lt;/P&gt;&lt;P&gt;poleAssembly:&lt;BR /&gt;{name: "assembly1", poleID: "b"}&lt;BR /&gt;{name: "assembly2", poleID: "b"}&lt;BR /&gt;{name: "assembly3", poleID: "c"}&lt;BR /&gt;{name: "assembly4", poleID: "d"}&lt;/P&gt;&lt;P&gt;In this case, the map should display only pole2 and pole3 because their globalIDs match at least one of the poleAssembly's poleIDs.&lt;/P&gt;&lt;P&gt;I'd like to accomplish this via a SQL statement in either QueryParameter.whereClause or FeatureLayer.definitionExpression.&lt;/P&gt;&lt;P&gt;I've tried the following-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;if let polesTable = polesLayer.featureTable as? ServiceFeatureTable {
     var params = QueryParameters()
     params.whereClause = "EXISTS (SELECT 1 FROM poleAssembly WHERE 
                            poleAssembly.poleID = poles.GlobalID)"
     let results = try await polesTable.queryFeatures(using: params)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This throws error 400: "Cannot perform query. Invalid query parameters."&lt;/P&gt;&lt;P&gt;i've also tried this as whereClause "GlobalID IN (SELECT poleID FROM poleAssembly)" with same error&lt;/P&gt;&lt;P&gt;Any help or explanation on how to achieve this filter would be appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 18:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/complex-sql-in-queryparameters-whereclause/m-p/1555942#M455</guid>
      <dc:creator>CalebMitcler</dc:creator>
      <dc:date>2024-11-06T18:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Complex sql in QueryParameters whereClause</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/complex-sql-in-queryparameters-whereclause/m-p/1556372#M456</link>
      <description>&lt;P&gt;I do not know of a direct way to achieve this. You cannot use a where clause on one table that references another table.&lt;BR /&gt;&lt;BR /&gt;Here's an option I can think of -&lt;BR /&gt;1) Query the pole assembly layer to find out all the poles they are attached to. If your data is coming from a feature service, you can make a custom REST web request with the `returnDistinctValues` parameter specified to get these values.&lt;BR /&gt;2) Take the values and either construct a where clause to use as a definitionExpression on the poles feature layer, or manually populate (&lt;A href="https://developers.arcgis.com/swift/api-reference/documentation/arcgis/servicefeaturetable/featurerequestmode" target="_self"&gt;ServiceFeatureTable.featureRequestMode&lt;/A&gt; = .manualCache) the poles feature table using that where clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;`&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 16:52:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/complex-sql-in-queryparameters-whereclause/m-p/1556372#M456</guid>
      <dc:creator>DiveshGoyal</dc:creator>
      <dc:date>2024-11-07T16:52:21Z</dc:date>
    </item>
  </channel>
</rss>

