5 Replies Latest reply on Sep 11, 2013 7:46 AM by dsousa-esristaff

    TOP 100

      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.


        • Re: TOP 100

          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


          • Re: TOP 100
            Thanks for the reply Anthony.

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

            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).

            • Re: TOP 100
              TOP, LIMIT is not currently supported.
              • Re: TOP 100
                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
                • Re: TOP 100
                  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?