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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:02:45+00:00 2026-06-04T10:02:45+00:00

I have a table with 100 or more columns that could have a value

  • 0

I have a table with 100 or more columns that could have a value “yes” or “no”.

I want to do a select according with the user’s request (checkbox values form) to extract all the rows that have the value at “yes”. So an example could be:

-User selects checkbox1 checkbox4 and checkbox7 and all the other are not selected.

The query could be:

select name from table where (col1 = yes or col4 = yes or col7 = yes) AND (col2= no and col3 = no and all the others columns are set to no)

How to implement this in an android query? And by the way this implementation that i found is not very elegant, could someone suggest me an other implementation for achieve that goal, please?

  • 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-04T10:02:47+00:00Added an answer on June 4, 2026 at 10:02 am

    Here’s the fixed code. It contains some test code.

            int numColumns = 10;
            boolean[] answers = new boolean[numColumns];
            String[] colNames = new String[numColumns];
            for(int i = 0; i < colNames.length; i++) {
                answers[i] = Math.random() > 0.5;
                colNames[i] = String.format("Col%d", i);
            }
            //-----------LOGIC STARTS HERE----------------
            // use a loop
            StringBuilder yesColumns = new StringBuilder();
            StringBuilder noColumns = new StringBuilder();
            for(int i = 0; i < answers.length; i++) {
                if(answers[i]) {
                    if(yesColumns.length() > 0)
                        yesColumns.append(" OR ");
    
                    yesColumns.append(colNames[i]).append("='yes'");
                }
                else {
                    if(noColumns.length() > 0)
                        noColumns.append(" AND ");
                    noColumns.append(colNames[i]).append("='no'");
                }
            }
    
            String yesCondition = yesColumns.toString();
            String noCondition = noColumns.toString();
            String query = String.format("select name from table where (%s) AND (%s)",
                                         yesCondition,
                                         noCondition);
            System.out.println(query);
            // SQLiteDatabase db;
            // Cursor cursor = db.rawQuery(query, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with more than 100 columns. I need to join it
I have a table with 100 or more rows that are created at runtime
I have a table containing around 100 columns, is it to possible to do
I have a table that looks like this: id count 1 100 2 50
I have a log table that contains job status. One of the columns is
Assuming I have a table with one field called ID that stores 100 different
I have a data table containing two columns (pattern and neworder) and cca 100
I currently have a site with a table that has Lat/Long float columns, and
I have a table where one or more entries with the same 'id' value
I have a table with 100 records with no PK. I need to add

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.