MariaDB select 不等于
MariaDB select where not equal
当然这会在几秒钟内被标记为欺骗,但我终究无法弄清楚这个查询有什么问题:
MariaDB [nextcloud]> describe oc_file_locks;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| lock | int(11) | NO | | 0 | |
| key | varchar(64) | NO | UNI | NULL | |
| ttl | int(11) | NO | MUL | -1 | |
+-------+---------------------+------+-----+---------+----------------+
4 rows in set (0.003 sec)
MariaDB [nextcloud]> select * from oc_file_locks where lock <> 0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'lock <> 0' at line 1
MariaDB [nextcloud]> select * from oc_file_locks where lock != 0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'lock != 0' at line 1
我是不是疯了,或者这行得通吗?我的 SQL 有点生疏了,但我不认为它有那么糟糕。
key
和 lock
是 reserved words。选择不同的名称,或将它们括在反引号中:
select * from oc_file_locks where `lock` <> 0;
当然这会在几秒钟内被标记为欺骗,但我终究无法弄清楚这个查询有什么问题:
MariaDB [nextcloud]> describe oc_file_locks;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| lock | int(11) | NO | | 0 | |
| key | varchar(64) | NO | UNI | NULL | |
| ttl | int(11) | NO | MUL | -1 | |
+-------+---------------------+------+-----+---------+----------------+
4 rows in set (0.003 sec)
MariaDB [nextcloud]> select * from oc_file_locks where lock <> 0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'lock <> 0' at line 1
MariaDB [nextcloud]> select * from oc_file_locks where lock != 0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'lock != 0' at line 1
我是不是疯了,或者这行得通吗?我的 SQL 有点生疏了,但我不认为它有那么糟糕。
key
和 lock
是 reserved words。选择不同的名称,或将它们括在反引号中:
select * from oc_file_locks where `lock` <> 0;