Skip to content Skip to sidebar Skip to footer

Search Multiple Columns In Sqlite Select From

I use this code to search for Column A. What modification should I make if I want to search Column A and Column B simultaneously? String sql = 'SELECT * FROM ' + TABLE_NAME +

Solution 1:

You can use OR to connect two expressions. However, both must be complete expressions:

SELECT ... WHERE ColA LIKE ? OR ColB LIKE ? ...

Solution 2:

Are you looking for UNION instead of OR? http://www.tutorialspoint.com/sqlite/sqlite_unions_clause.htm

Solution 3:

Make two differrent query. And combine results by union keyword.

select * from TABLE_NAME where columnA like ? orderby columnA limit 100
union
select * from TABLE_NAME where columnB like ? orderby columnA limit 100

Solution 4:

This solved my problem:

Stringsql="SELECT * FROM " + TABLE_NAME +
                " WHERE " + ColumnA + " OR " + ColumnB + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100";

I should use one select statement.

Post a Comment for "Search Multiple Columns In Sqlite Select From"