I'm using sqlite right now and wants to know if any SQL query exists to get all the names having searched name as whole or some part of name. I have saved all names in one column i.e. "name" column and wants to get like if I have saved "abc", "xyz" and "abc xyz" as names and searched abc then it should give results like: "abc" and "abc xyz" and similar for for other names....
Asked
Active
Viewed 1.3k times
4 Answers
3
If the search term can be in any part of the name
column, surround your search term with wildcard characters ('%') and use the LIKE
operator:
WHERE
name LIKE '%abc%'
If you want all name
s that start with "abc":
WHERE
name LIKE 'abc%'
Or all name
s that end with "abc":
WHERE
name LIKE '%abc'

Cᴏʀʏ
- 105,112
- 20
- 162
- 194
-
@HusnainIqbal: I see you're new here; if an answer helped you, vote it up. If an answer provided you with a solution, mark it as "accepted" by clicking the green check mark outline to the left of it. You can only accept one, so pick which one you feel is best. – Cᴏʀʏ Dec 27 '12 at 14:10
1
you need to use Like operator for this situation
SELECT *
FROM table
WHERE Name LIKE '%abcd'

A.Goutam
- 3,422
- 9
- 42
- 90
0
SQLite3 supports regular expressions, merely need to put where name REGEXP 'abc'
as your where clause. Hope that helps...
0
If you want:
"abc", "xyz" and "abc xyz" as names
search by "abc"
results like: "abc" and "abc xyz"
You should use field like "abc%"

Michael Durrant
- 93,410
- 97
- 333
- 497