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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:28:35+00:00 2026-06-01T17:28:35+00:00

I have a database table with several columns in it. I want to select

  • 0

I have a database table with several columns in it. I want to select certain rows by comparing a string entered by a user and select records based on their entry. I have the following code:

SearchbyIngredient.Java

    final Button searchbutton1 = (Button) findViewById(R.id.searchbutton1);
searchbutton1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
Cursor temp = dbIngredientHelper.getDrinks(textView.getText().toString());
        String ingred = temp.getString(0);
        Context context = getApplicationContext();
        iadapter = new IngredientAdapter(temp);
        myListView.setAdapter(iadapter);
    }
});
}

IngredientHelper.Java

public Cursor getDrinks(String drinkName) throws SQLException{
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(TABLE_NAME2);
    String selection = COLUMN_INGRED1 + "= ' " + drinkName + "'";
    String[] asColumnsToReturn = new String[] { COLUMN_ID2, COLUMN_DRINKNAME, COLUMN_INGRED1, COLUMN_AMT1, COLUMN_INGRED2, COLUMN_AMT2, COLUMN_INGRED3, COLUMN_AMT3, COLUMN_INGRED4, COLUMN_AMT4 };
    Cursor mCursor2 = queryBuilder.query(dbSqlite, asColumnsToReturn, selection, null, null, null, COLUMN_DRINKNAME);
    /*Cursor mCursor = dbSqlite.query(true, TABLE_NAME2, new String[]{
            COLUMN_DRINKNAME}, 
            COLUMN_INGRED1 + "= ' " + drinkName + "'", null, null, null, null, null);
    if (mCursor != null){
        mCursor.moveToFirst();
    }*/
    mCursor2.moveToFirst();
    return mCursor2;
}

My question is regarding

String selection = COLUMN_INGRED1 + "= ' " + drinkName + "'";

This code currently works, however it only finds entries with the user’s text in COLUMN_INGRED1 (only a single column in the code). How can I format the statement or make a series of statements so that it also looks for the user’s text in COLUMN_INGRED2, COLUMN_INGRED3 and COLUMN_INGRED4? Thank you

  • 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-01T17:28:37+00:00Added an answer on June 1, 2026 at 5:28 pm

    Standard SQL applies, use an OR:

       COLUMN_INGRED1 + "= ' " + drinkName + "' OR " COLUMN_INGRED2 + "= '" +drinkName + "'" ...;
    

    Note that = will do an exact match, you might want to look into the LIKE operator.

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

Sidebar

Related Questions

I have a database table with several columns; most of them are VARCHAR(x) type
I have one database table which contains 8 columns. One of the columns is
I have a database table where the user marks files to be downloaded. Subsequently,
I have a Database table that I want to display in a DataGridView. However,
I'm helping implement a SQL Server 2008 database and I have several columns that
I have a mysql database table called character with columns like name, strength, intelligence,
I have a huge table in a database and I want to split that
I'm implementing a database where several tables have string data as candidate keys (eg:
I have several database tables that just contain a single column and very few
I have an Access database (in Access 2003) with several tables, and data must

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.