1

everyone;

I am working on a database where path information are stored, one simplified table is shown below

path_id | path value
1         //a/b/c/d
2         //a/b/e
3         //a/b
4         //a/bcd

So here is the question, how can I get information where has '//a/b' as the prefix? In this case, the result should be:

path_id | path value
1         //a/b/c/d
2         //a/b/e
3         //a/b

I am seeking for a more elegant and optimized query, other than using logic operators like 'OR'. Thanks.

4

2 回答 2

3
SELECT * FROM YourTable WHERE path_value like '//a/b/%' OR path_value = '//a/b' 

Note the extra slash before the wild card in the first part of the WHERE statement. This will exclude //a/bcd.

于 2012-09-18T20:10:29.437 回答
0

the % acts as a wild card so it anything can follow that part.

SELECT * FROM tableName WHERE path_value like '//a/b/%' OR path_value = '//a/b'
于 2012-09-18T20:08:44.437 回答