Reputation: 93
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....
Upvotes: 2
Views: 14163
Reputation: 3494
you need to use Like operator for this situation
SELECT *
FROM table
WHERE Name LIKE '%abcd'
Upvotes: 1
Reputation: 107536
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'
Upvotes: 3
Reputation: 96484
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%"
Upvotes: 0
Reputation: 34657
SQLite3 supports regular expressions, merely need to put where name REGEXP 'abc'
as your where clause. Hope that helps...
Upvotes: 0