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

  • Home
  • SEARCH
  • 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 8108355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:05:09+00:00 2026-06-06T01:05:09+00:00

android noob… I have two tables, with a one to many relationship between country_tbl

  • 0

android noob… I have two tables, with a one to many relationship between country_tbl and city_tbl, and I would like to concatenate values from city_tbl.landmark_col with GROUP_CONCAT() and INSERT all the landmark_col values as a single String into country_tbl.all_landmarks column. The SQL seems to require a nested SELECT to concatenate the landmark_col values before passing them to the country_tbl… something like:

UPDATE country_tbl 
SET country_tbl.all_landmarks = (SELECT landmarks_col FROM 
                                    (SELECT country_id, group_concat(landmarks_col) 
                                            FROM city_tbl INNER JOIN country_tbl
                                            ON country_tbl.country_id = city_tbl.country_id
                                            GROUP BY country_tbl.country_id) 
                                    AS country_landmarks      
                                WHERE country_tbl.country_id = country_landmarks.country_id)
WHERE
EXISTS (
    SELECT *
    FROM country_landmarks
    WHERE country_tbl.country_id = country_landmarks.country_id
);

Not sure if nested select statements are even supported or if just too resource intensive… there must be a better way, as it seems like using rawQuery is not the best solution. Not sure if I should be creating temporary tables, using ContentProviders, or passing a cursor…?

  • 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-06-06T01:05:10+00:00Added an answer on June 6, 2026 at 1:05 am

    I answered this by splitting up the long SQL query into two parts. First I created a subquery with a SQLiteQueryBuilder and ran using rawQuery to get a two column cursor with the location_id and the group_concat values for the landmark_names. I was then able to cycle through the cursor to update the country table with each of the appropriate concatenated values of all the landmark names for that country.

    The query below is a tad more complicated than the question above (which I simplified before posting), only because I had to join a landmarks list table with another landmark_type table by the landmark_type_id, and my real goals was to concatenate the shorter list of landmark_type by country, not the long list of all the landmark_names by country. Anyway, it works.

        public void UpdateCountryLandmarks() throws SQLException {
        Cursor c = null;
        String subquery = SQLiteQueryBuilder.buildQueryString(
                // include distinct
                true,
                // FROM tables
                LANDMARK_TYPE_TABLE + "," + LANDMARKS_TABLE,
                // two columns (one of which is a group_concat()
                new String[] { LANDMARKS_TABLE + "." + LOCATION_ID + ", group_concat(" + LANDMARK_TYPE_TABLE + "." + LANDMARK_TYPE + ",\", \") AS " + LANDMARK_NAMES },
                // where
                LANDMARK_TYPE_TABLE + "." + LANDMARK_ID + "=" + LANDMARKS_TABLE + "." + LANDMARK_TYPE_ID,
                // group by
                LANDMARKS_TABLE + "." + LOCATION_ID, null, null, null);
    
        c = mDb.rawQuery(subquery, null);
    
        if (c.moveToFirst()) {
            do {
                String locationId = c.getString(c.getColumnIndex(LOCATION_ID));
                String landmarkNames = c.getString(c.getColumnIndex(LANDMARK_NAMES));
                ContentValues cv = new ContentValues();
                cv.put(LANDMARK_NAMES, landmarkNames);
                mDb.update(COUNTRY_TABLE, cv, LOCATION_ID + "=" + locationId, null);
            } while (c.moveToNext());
        }
    
        c.close();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im an Android noob, coming from objC, I have a very stupid question (project
I'd like to try org.apache.commons.lang.StringUtils in my Android project. I have downloaded commons-lang3-3.1.jar and
i have to show some operations in Android,,, but Im having some noob problem,
question worth million dollars for a noob like me. I would like to store
Okay, first, I'm a noob at android programming. I have taken some Java, but
I've been learning Android for about two weeks now (expert in as2/3). I have
I am a noob learning Android via a book, i have a quick question.
I am a complete Android and C in general noob, I have done a
first of all, i'm a noob at java programing for android. Now, I have
I am a noob to Android (and Java). I have successfully setup Eclipse and

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.