SQLite query, 'LIKE'
Execute following Query:
select name from memberdb where name like '% LIM %' OR name like "LIM %" OR name like "% LIM" OR name like "LIM"
LIKE query in sqlite3
SQLite does not support an enhanced LIKE
operator which supports the syntax you are using (though SQL Server does). SQLite does support the REGEXP
operator, but it needs to be loaded. However, we can phrase your query using LIKE
as follows:
SELECT *
FROM customers
WHERE city LIKE 'a%' OR city LIKE 'c%' OR city LIKE 's%';
Android SQLite Like query
The %
wildcards must be part of the string:
... + " LIKE '%" + strname+ "%'", ...
Please note that this code will blow up when the string contains a quote.
You should use parameters instead:
db.query(true, DATABASE_TABLE,
new String[] {KEY_ROWID,KEY_FAULTREF,KEY_WORKNUM,KEY_ORIGNUM,KEY_REPBY,KEY_REPDATTIM,KEY_DESCRIPTION},
KEY_REPBY + " LIKE ?",
new String[] { "%" + strname + "%" },
null, null, null, null);
How to perform LIKE query in Sqlite with a List of query String
But I want to combine this two statement in one single line.
Why you just don't use OR operator between LIKE conditions ? :)
I mean
SELECT * FROM table_one WHERE dates LIKE '%dayOfMonth":3%' OR dates LIKE '%dayOfMonth":5%'
General rule here: don't use REGEXP in WHERE conditions if you don't have to. With regexp you lose INDEX search advantage..
Android Sqlite Like operator with OR statements
You never bind parameters for the second and third LIKE
expressions in your query. Edit: If you want to use the same LIKE
expression several times, you still need to bind however many times you have placeholders.
string[] a = new string[3];
string likeString = '%' + query + '%';
a[0] = '%' + query + '%';
a[1] = '%' + query + '%';
a[2] = '%' + query + '%';
var sqldb_query = "SELECT * FROM MYTABLE WHERE Col_1 LIKE ? OR Col_2 LIKE ? OR Col_3 LIKE ?";
var sqldb_cursor = myDb.RawQuery(sqldb_query, a);
How to query in sqlite using like keyword with column name?
The string concatenation operator in SQLite is ||
. And you can express this as a JOIN
:
SELECT A1
FROM A JOIN
B
ON A.A2 LIKE '%' || B.B2 || '%'
WHERE B.B1 = 1;
Note that ||
is the SQL standard string concatenation operator. +
is overloaded in just a handful of databases owned by Microsoft (mostly).
SQLite - Using LIKE Clause with AND Clause
Change query as below
String selection = COLUMN_1 + " LIKE ? AND " + COLUMN_2 + " =? AND " + COLUMN_3 + " =?"
SQLite: Select using LIKE '%?%' with rawQuery
The Problem is with the SQL query you have used.
you are giving ? A String which is not acceptable for prepare statements. select distinct * from table_name where X like '%?%';
is not correct because ?
will be a string with double quotation inside a quotation like '%"your_string"%'.
instead write:
select distinct * from table_name where X like ?;
and for ?
use "'%your_string%'
". you can apply this to your array of string too.
Related Topics
What's the R Equivalent of SQL's Like 'Description%' Statement
How to Compare Two Columns for Equality in SQL Server
Referencing Current Row in Filter Clause of Window Function
Pivot Without Aggregate Function in Mssql 2008 R2
How to Bulk Insert Only New Rows in Postresql
Sqlite String Contains Other String Query
Indexes and Multi Column Primary Keys
How to Decrypt Stored Procedure in SQL Server 2008
Rodbc SQLsave Table Creation Problems
How to Combine Results of Two Queries into a Single Dataset
Adding 'Go' Statements to Entity Framework Migrations
Diagnosing an Oledb Exception When Quering Excel 2010
How to Exclude a Column from Select Query
SQL Efficient Way to Join a Table Where All Values Exist