Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6169183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:48:50+00:00 2026-05-23T22:48:50+00:00

public Cursor fetchAllPBs() { String sql = SELECT * FROM + CAPTURES_TABLE + GROUP

  • 0
public Cursor fetchAllPBs() {       
    String sql = "SELECT * FROM " + CAPTURES_TABLE + " GROUP BY " + KEY_CAPTURES_SPECIES 
            + " ORDER BY " + KEY_CAPTURES_POUNDS + " DESC, " + KEY_CAPTURES_OUNCES + " DESC, " + KEY_CAPTURES_DRAMS + " DESC;";
    Cursor c = mDb.rawQuery(sql, null);
    if(c != null) {
        c.moveToFirst();
    }
    return c;
}

Hi,

I want the above query to return me the user’s personal best for each species, that is, the heaviest item within each species. Testing it properly recently I’ve realised a problem. I’m still relatively new to SQL with this project…

Say I add a ‘Chub’ to my database of 7lb 6oz 0drms, then add another of 7lb 2oz 0drms – it will return the more recently added fish as the PB and not the biggest (the 7lb 2oz one). However if I then add another Chub of 8lb 0oz 0drms it will return the 8lb fish – it seems it’s not properly ordering them by the Ounces and probably by that I assume the drams too.

Can anyone see what’s wrong here and suggest a solution?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:48:51+00:00Added an answer on May 23, 2026 at 10:48 pm

    First, you need a subquery to determine the heaviest fish per species.
    Second, your weight is split in 3 columns, so you need to add them in someway. I choose to just add them with multiplication, should be sufficient for getting the max.

    SELECT *
    FROM CAPTURES_TABLE AS C1
    WHERE (100*Pounds+10*Ounces+Drams) = 
          (SELECT MAX(100*Pounds+10*Ounces+Drams) 
          FROM CAPTURES_TABLE AS C2
          WHERE C2.SPECIES=C1.SPECIES)
    ORDER BY pounds DESC, ounces DESC, drams DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to get the value of Count column from cursor. public Cursor getRCount(String
See title for explanation. Here is the method I'm using: public Cursor getClientByName(String name)
I have been using the following code to query one table: public Cursor fetchFilteredItemsNearSortedByDistance(String
Can I query from 2 tables like this? public Cursor getSen_List(long id_thsen ) {
From my main.java: Cursor c = db.getDue(); String[] columns = new String[] { _id,
I use ContentProvider, and SQLiteQueryBuilder : @Override public Cursor query(Uri uri, String[] projection, String
I'm using Content Providers. The Content Provider uses SQLBuilder: public Cursor query(Uri uri, String[]
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public class Test { public static void main(String[] args) { } } class Outer
public class Item { ... } public class Order { public List<Item> Items ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.