Skip to content

<>,!=

运算符说明

<>, != 运算符仅当左操作数不等于右操作数时返回 true

语法结构

> SELECT x <> y;

示例

mysql> SELECT 2 <> 2;
+--------+
| 2 != 2 |
+--------+
| false  |
+--------+
1 row in set (0.01 sec)
create table t1 (spID smallint,userID bigint,score int);
insert into t1 values (1,1,1);
insert into t1 values (2,2,2);
insert into t1 values (2,1,4);
insert into t1 values (3,3,3);
insert into t1 values (1,1,5);
insert into t1 values (4,6,10);
insert into t1 values (5,11,99);

mysql> select userID,spID,score from t1 where userID=spID and userID<>score;
+--------+------+-------+
| userid | spid | score |
+--------+------+-------+
|      1 |    1 |     5 |
+--------+------+-------+
1 row in set (0.00 sec)