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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:21:22+00:00 2026-06-11T19:21:22+00:00

I have a cars sqlite database with one table that has 3 columns: year,

  • 0

I have a cars sqlite database with one table that has 3 columns: year, make and model. With the below query, I can search on a single phrase like “ford” and it will display all ford results, or “1964” and I’ll get all cars from that year. But “1964 ford” returns “no results found” – or null. How can the query be modified so that I can enter search terms from all 3 columns like “1964 ford mustang”? Yes, I know there’s no such thing as a 1964 ford mustang, it’s 1964 and a half. But there is a row for a 1964 ford mustang in my DB, so let’s use “1966 ford mustang” as the example.

    public Cursor searchDB(String query) {  
    return db.query(true, DB_TABLE, new String[] { KEY_ROWID, KEY_YEAR, KEY_MAKE, 
    KEY_MODEL }, KEY_YEAR + " LIKE" + "'%" + query + "%' OR " + KEY_MAKE +  
    " LIKE" + "'%" + query + "%' OR " + KEY_MODEL + " LIKE" + "'%" + query + "%'",  
    null, null, null, null, null);  
}

I’ve tried using AND in place of + but that crashes. I’m using android 2.2.

  • 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-11T19:21:23+00:00Added an answer on June 11, 2026 at 7:21 pm

    The reason it’s not working is your column LIKE %query% statements. That’s saying that the value has to contain your query exactly with any number of characters on either end. So "1964" LIKE "%1964 mustang%" would fail but "1964 mustang" LIKE "%1964%" would give you the proper result.

    If you split your query string by spaces and query each column against each split string, that would likely give you the results you’re looking for.

    UPDATE: Snippet for splitting the string and forming the query.

    public Cursor searchDB(String query) {
        /* Example: query = "1964 ford mustang" */
    
        String[] parts = query.split(" "); /* Should split to {"1964", "ford", "mustang"} */
    
        String queryString = "";
        for(int i = 0; i < parts.length; i++) {
            queryString += KEY_YEAR + " LIKE '%" + parts[i] + "%' OR ";
            queryString += KEY_MAKE + " LIKE '%" + parts[i] + "%' OR ";
            queryString += KEY_MODEL + " LIKE '%" + parts[i] + "%'";
            if(i != (parts.length - 1)) {
                queryString += " OR ";
            }
        }
    
        return db.query(true, DB_TABLE, 
            new String[] { KEY_ROWID, KEY_YEAR, KEY_MAKE, KEY_MODEL }, 
            queryString, null, null, null, null, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One car must have one owner, and an owner can have many cars.
I have Car (table cars ) method that has_many owners (table owners ). How
I have a question regarding DataBase design. I have a Entity Table named: CARS
I have table cars: Id int, Model nvarchar(max), DateOfProduction (datetime). And data like: 1
Say I have two tables, 'cars' and 'properties', linked by table 'car_properties'. I can
I have a table looking like this created with sqlite. CREATE TABLE Cars (
i have a table called Cars and the primary key of the table is
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
i have a table of resources (lets say cars) which i want to claim
I am using MySQL DB. I have a cars table, by describing this table

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.