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 7626021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:16:11+00:00 2026-05-31T05:16:11+00:00

I have one group table with a recursive relation, so each record has a

  • 0

I have one group table with a recursive relation, so each record has a parent_id. Given a group, I need to get all the student (each belong to a group) names in all its subgroups, but ordered by student name.

Do you know if there is any “easy” way to do it? If I have to do multiple queries, then I should order the results of the different Cursors, but Cursor has no orderBy().

Any ideas? Thank you so much!

  • 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-31T05:16:12+00:00Added an answer on May 31, 2026 at 5:16 am

    As SQLite does not support recursive queries I implemented the select with two steps:

    First, I have a method called getRecursiveDiningGroupIdsAsString() that retreives all the group ids recursively whose parent id is the one you pass by parameter. The result is a String in the form of: “(2, 3, 4)” so you can later use it in an IN clause. The method looks like:

    public String getRecursiveDiningGroupIdsAsString(int depth, long diningGroupId) {
        Cursor childDiningGroups = mDatabase.query(
                "group",
                new String[] {"_id"},
                "parent_id = "+diningGroupId,
                null, null, null, null
        );
        String recursiveDiningGroupIds = "";
        while (childDiningGroups.moveToNext()) {
            long childDiningGroupId = childDiningGroups.getLong(childDiningGroups.getColumnIndex("_id"));
            recursiveDiningGroupIds += getRecursiveDiningGroupIdsAsString(depth+1, childDiningGroupId);
        }
        recursiveDiningGroupIds += diningGroupId;
        if (depth > 0) {
            recursiveDiningGroupIds += ", ";
        } else {
            recursiveDiningGroupIds = "("+recursiveDiningGroupIds+")";
        }
        return recursiveDiningGroupIds;
    }
    

    Once I have the group ids I need, I just do a simple query using the ids returned by the previous method and that is it!

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called users and each user can belong to one group,
I have a table like this one: id group value 1 GROUP A 0.641028
I am a student this is homework... I have one table with four columns:
I have one table in MYSQL It has data like Id Name 1 test
I am using mysql 5.0.51b. I have one table named xyz. xyz table has
I have one table and I need to check if two users, for whom
I have one table called gallery . For each row in gallery there are
I have 2 tables with relation in between. table one is holding groups with
I have one image table and image view status table. In each click of
I have two tables user (one) and transaction (many) and I need to get

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.