Born Protege Born Protege - 17 days ago 4
SQL Question

SQL : Confused with WildCard operators

what is difference between these two sql statements

1- select * from tblperson where name not like '[^AKG]%';

2- select * from tblperson where name like '[AKG]%';


showing same results: letter starting from a,k,g

vkp vkp
Answer

like '[^AKG]% -- This gets you rows where the first character of name is not A,K or G. ^ matches any single character not in the specified set or a specified range of characters. There is one more negation not. So when you say name not like '[^AKG]%' you get rows where the first character of name is A,K or G.

name like '[AKG]% -- you get rows where the first character of name is A,K or G.

The wildcard character [] matches any character in a specified range or a set of characters. In your case it is a set of characters.

So both the conditions are equivalent.