TOP 100

4118
5
10-14-2012 06:06 AM
Drew
by
Occasional Contributor III
Is there any SQL that is valid with the FGDB that will help me limit the results returned?
I have tried TOP, LIMIT etc..  but none work.

I could do it all in  code, but I would rather retrieve only the records i need from the table.

I am using the .NET wrapper.

Thoughts?

Drew
0 Kudos
5 Replies
AnthonyGiles
Frequent Contributor
Andrew,

The help states the following:

SELECT * FROM forms the first part of the SQL expression and is automatically supplied for you. Because you are selecting columns as a whole, you cannot restrict the SELECT to return only some of the columns in the corresponding table; thus, the hard-coded SELECT * syntax. For this reason, keywords like DISTINCT, ORDER BY, GROUP BY, and so on, cannot be used readily in a SQL query except when using subqueries.

So what you could try and do (I must warn I have not tried this) is create a sub query that performs the limit then use the IN command to select out the records that you need, I.e:

objectID IN (select objectID from (select objectID, column from 'table' where 'expression' order by 'column' limit 100))

I say don't know if this will work but you never know

Regards

Anthony
0 Kudos
Drew
by
Occasional Contributor III
Thanks for the reply Anthony.

I am able to get a full SQL query against the table using the below code..

C#
string sql = "SELECT * FROM " + tableName
RowCollection rows = geodatabase.ExecuteSQL(sql);


From my knowledge the ExecuteSQL function will take raw valid SQL outlined in the doc's but the doc's do not show any way to limit the returned result (i.e LIMIT or TOP).

Drew
0 Kudos
LanceShipman
Esri Regular Contributor
TOP, LIMIT is not currently supported.
0 Kudos
TomHoober
New Contributor II
Lance are there any plans to support TOP functionality or any of the SELECT modifiers (ie DISTINCT)? I think its odd that there isn't a way to access full SQL query abilities.  Thanks
0 Kudos
DavidSousa
New Contributor III
I believe you will find that SELECT DISTINCT has worked all along.

There are no immediate plans to implement SELECT TOP.  I am not convinced that it is particularly useful.  If you want the equivalent of SELECT TOP 100 * from xxx, why not just keep track of how many rows you have read in and then stop after you hit 100?
0 Kudos