Search code examples
javagoogle-app-enginegoogle-cloud-datastoremax

Find the max value in a column of app engine datastore


I have a table in google app engine datastore as ItemDatawith columns as below.

item_no, letter, f_no, s_no, t_no

I need to get the max value in item_no column.

How can I achieve this?


Solution

  • Here is my solution.

    PersistenceManager pm = PMF.get().getPersistenceManager();
    
    Query q = pm.newQuery("SELECT item_no FROM " + ItemData.class.getName()
                        + " ORDER BY item_no DESC RANGE 0,1");