1

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....

4

4 回答 4

3

如果搜索词可以在name列的任何部分,请用通配符 ('%') 将搜索词括起来并使用LIKE运算符:

WHERE
    name LIKE '%abc%'

如果你想要所有以“abc”开头name的s :

WHERE
    name LIKE 'abc%'

或者所有name以“abc”结尾的:

WHERE
    name LIKE '%abc'
于 2012-12-26T19:45:24.753 回答
1

对于这种情况,您需要使用 Like 运算符

 SELECT  * 
    FROM table  
    WHERE Name  LIKE '%abcd' 
于 2012-12-26T18:54:23.383 回答
0

SQLite3 supports regular expressions, merely need to put where name REGEXP 'abc' as your where clause. Hope that helps...

于 2012-12-26T19:16:39.400 回答
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%"

于 2012-12-26T19:41:36.310 回答