Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is it possible to get just one row/record returned from a feature service query -- similar to the TOP, ROWNUM and LIMIT in database queries? Of course, OBJECTID "1" is not guaranteed. Is there a trick that I've missed?

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/query?where=OBJECTID%3D1

SQL Server / Access: SELECT TOP 1 * FROM CUSTOMERS;
Oracle: SELECT * FROM CUSTOMERS WHERE ROWNUM <= 1;
MySQL: SELECT * FROM CUSTOMERS LIMIT 1;
PostgreSQL: SELECT * FROM CUSTOMERS LIMIT 1;

share|improve this question
    
maybe ORDER BY? –  Krystian Mar 4 '13 at 19:23
    
How does that get just one record? I want a single random record, if available, to check on a service. I want to use the least possible resources on the server. –  awesomo Mar 4 '13 at 19:32
    
oh sorry I didn't understand you before –  Krystian Mar 4 '13 at 20:06
    
OData has a top option‌​. If you think Esri should support OData compliant mapservices, please vote for this idea. –  Kirk Kuykendall Mar 4 '13 at 20:39
1  
Just voted for it.. –  awesomo Mar 4 '13 at 21:06

1 Answer 1

If you wanna to get only 1 record try use TOP statement.

ie: OBJECTID IN (SELECT TOP 1 OBJECTID FROM 'customers' ORDER BY OBJECTID))

but you have note that this is bypass because TOP and LIMIT arent supported by geodatabase http://forums.arcgis.com/threads/68997-TOP-100

EDIT I digged deeper cause this subject seems to me as interesting, and I found this kind of script: http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=E780BB87-1422-2418-7FD8-A1A0D8167AAF it returns a subset of features with the same schema as oryginal. It's made in python so, maybe you could use it as geoprocessing service as gate to your sql queries.

EDIT2 From more research i think that using TOP LIMIT or ROWNUM depends on your DB engine. But the main clue is to use it as subquery - because we only can get access from WHERE part of statement by using API

NOTE FOR 10.2 USERS: This will not work because it defaults to standardized queries which don't allow subqueries. You can turn off standardized queries, but this is not recommended since it makes SQL injection attacks easier to perform.

share|improve this answer
    
Interesting... however none of these worked on the sampleserver3 above for 311 incidents? OBJECTID IN (SELECT TOP 1 OBJECTID FROM Incidents); OBJECTID = (SELECT TOP 1 OBJECTID FROM Incidents); OBJECTID IN (SELECT * OBJECTID FROM Incidents LIMIT 1); OBJECTID = (SELECT * OBJECTID FROM Incidents LIMIT 1) –  awesomo Mar 4 '13 at 20:21
    
at this moment I can not do any query on esri sampleserver3, and I don't have access to my product. server right now so I can't check if its works. but it should, a can perform this kind of query in my arcgis desktop for query dispalying features from layer (arcgis desktop 9.3.1) so it should works the same on the server side... my arcgis desktop query is exact: OBJECTID IN (SELECT TOP 20 [OBJECTID] FROM [boreholes_db].[dbo].[DEEPBOREHOLESCLASS] ORDER BY NEWID()) –  Krystian Mar 4 '13 at 20:28
    
I wouldn't be surprised if that worked in desktop, but it still requires knowing which database is behind the service. I cannot get that query to work on my services -- using SQL Server and SQL Server syntax. OBJECTID IN (SELECT TOP 1 [OBJECTID] FROM [DougTest].[dbo].[PLSS]) –  awesomo Mar 4 '13 at 21:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.