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 there a way to use a SELECT TOP (n) within ArcGIS desktop? Is appears that since the ArcGIS query builder is effectively building the SQL statement after the WHERE clause, that this may not be possible.

Here is a typical SQL example of usage:

SELECT TOP 3 * FROM Layer

share|improve this question
1  
Note that TOP and LIMIT are not supported in file geodatabases: forums.arcgis.com/threads/68997-TOP-100 –  blah238 Jan 15 '13 at 7:34
add comment

2 Answers 2

up vote 4 down vote accepted

If your underlying database supports sub queries, you can build a query with a TOP N that returns ObjectIds (or any other field) and use that in your definition query.

OBJECTID IN (*query here*)

For example, here's a SQL Server query for a TOP 20, random selection: enter image description here

The above query will return 20 different rows each time the map or attribute table is refreshed. This also could come in handy for an ArcMap practical joke for less experienced users (April Fools is less than a month away).

Of course, the sub query doesn't have to be a TOP N query nor do you need to use a unique id. Maybe work up a query to find duplicates:

FIRE_ID IN (SELECT FIRE_ID
FROM [SandboxGeodb].[dbo].[TESTFEATURECLASS] GROUP BY FIRE_ID HAVING COUNT(FIRE_ID) > 1)

share|improve this answer
    
nice! I can see this giving a loot of trouble to some users.."what did you do to the database???" –  George Mar 6 '11 at 13:53
1  
While I was really hoping I could do this with shapefiles, it appears I cannot. However, this appears to be a very good way of solving the issue when calling data from a SQL data source that supports SELECT TOP queries. Thanks. –  RyanDalton Mar 9 '11 at 17:04
    
You can use such queries within the Definition query, but is there any workaround to use them within Select by Attribute tool? It already has this SELECT FROM part pre-populated. –  Alex Tereshenkov Feb 20 at 7:51
add comment

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.