Select to view content in your preferred language

SQL DISTINCT

1358
6
01-15-2013 08:55 AM
GordonBooth
Deactivated User
I???m working on a project to identify sexual offenders by their alias name(s). When I do a query on an alias name it displays the master name (given name) and location. However an offender with the master name of James may have multiple alias???s like: Jim, Jimmy and Jimmie.  I want to remove the duplicate results and display the master name and location only once. Can I remove the duplicates with a SQL DISTINCT statement? Does anyone have an example of a SQL DISTINCT in a query.where? I???m using ArcGIS 10 Desktop and Server.
Thanks
0 Kudos
6 Replies
JustinPeters
Deactivated User
I also have a need for a DISTINCT in a query.where anyone have suggestions?
0 Kudos
JustinPeters
Deactivated User
Found a workaround since DISTINCT is not supported, from http://blogs.esri.com/esri/arcgis/2009/10/07/using-javascript-to-populate-a-combobox-with-unique-val...

//Loop through the QueryTask results and populate an array
        //with the unique values
        var features = results.features;
        dojo.forEach (features, function(feature) {
          zone = feature.attributes.ZONING_TYPE;
          if (!testVals[zone]) {
            testVals[zone] = true;
            values.push({name:zone});
          }
        });
0 Kudos
DianaBenedict
Frequent Contributor
I have never tried using the esri.tasks.StatisticDefinition object but it looks like you might be able to use the statisticType = 'count' and then you could use the returned featureset to obtain your unique list based on the onStatisticField.

Once you have setup the StatisticsDefinition object then you can use it in your Query Object (esri.tasks.Query)

Query.outStatistics

However, note that there seems to be the following requirements:
1) Requires ArcGIS Server service version 10.1 or greater (As of v2.6)
2) outStatistics is only supported on layers/tables where supportsStatistics is true.
3) If outStatistics is specified the only other query parameters that will be used are groupByFieldsForStatistics, orderByFields, text, timeExtent and where.

What I do not know is if the StatisticsDefinition only permits statistics on integer fields or if you can use the statistics type = "count" for character fields.

Refer to the Help doc for additional info:
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#query
0 Kudos
ReneRubalcava
Esri Frequent Contributor
The REST API has a "returnDistinct" option for Query in 10.1 SP1, but I have not tried it yyet.
http://resources.arcgis.com/en/help/rest/apiref/query.html

Maybe you could add it to the query object, and try it. If that doesn't work you could experiment with just using esri.request() to do the query manually.
0 Kudos
BradBarnell
Regular Contributor
The return distinct option in 10.1 SP1 is not yet available in the js api.
0 Kudos
NianweiLiu
Frequent Contributor
In ArcMap, File--add a query layer, then create a SQL query with DISTINCT.
Note although it says add a layer, you do not need to have spatial column. The query will be added as a TABLE.

Then run a where="1=1" on this table.
0 Kudos