Reputation: 10148
Hi all i have the following table called student in SQLite database.
this is my table structure
id name
-----------------------
"3" "Babu Qw"
"2" "Ganesh Babu"
"1" "Murali Abb"
"4" "ganesh1 Babu"
"5" "hari murali"
"10" "Abbash abc"
name field is combined by first name and last name. for example "Babu Qw" Babu is the first name and Qw is the last name its separated by a space.
and name is the input field where 'ba' is my input parameter.(Ex .. name like 'ba')
now i want to fetch the records whatever name (first name or last name ) starts with 'ba' not by any middle character.
output would be:
id name
-----------------------
"3" "Babu Qw"
"2" "Ganesh Babu"
"4" "ganesh1 Babu"
here "Abbash abc" (first name Abbash or last name abc does not starts with ba) so that "Abbash abc" not listed.
Upvotes: 3
Views: 6518
Reputation: 66697
This should do the trick:
select id, name
from table
where name like 'Ba%' or name like '% Ba%'
Upvotes: 6
Reputation: 10294
Can you use REGEXP with SQLite? Something like
SELECT * FROM table WHERE name REGEXP('^ba.*') OR name REGEXP('^.* ba.*');
Note : I'm not really at Regular Expression so this one may be false, or you may even do that in just one. Well you see the idea.
Upvotes: 1