Sql 中 不等于 可以用 以下方式表示:
select * from [TableName] where not id = 1; (注意不能写成 select * from [TableName] where id not = 1;)
select * from [TableName] where id != 1;
select * from [TableName] where id <> 1;(最常用)
通配符:
%表示匹配0个,1个或多个字符。
select * from [TableName] where address like '%' 不会检索出address值为null的行。
_表示只匹配一个字符,不能多也不能少。
集合通配符[]:(貌似只有微软的数据库支持,以下是Sqlserver中的例子,Access的写法不太一样)
找出所有名字以G或X开头的用户。
select * from Users where name like '[GX]%'
否定上面的语句有三种写法:
1. select * from Users where name like '[^GX]%'
2. select * from Users where name not like '[GX]%'
3. select * from Users where not name like '[GX]%'(这个是not的通用语法,表示否定后面的这条语句)
注意:不要过度使用通配符,如果能用其他操作符的能达到相同目的,请使用其他操作符。
如果确实需要使用通配符,也尽量不要把它们用在搜索的开始处,因为这样搜索是最慢的。