使用 not 运算符的限制无法正常工作 MySql
Limit with not operator is not working correctly MySql
我正在使用下面的查询,在 where 和 limit 中使用 not 运算符。我无法获得正确的数据排序(没有限制子句是不同的,并且数据的限制排序是不同的)。
SELECT DISTINCT(id) FROM `table` WHERE (1 AND id_type!=1) ORDER BY id desc LIMIT 2
Table Structure with sample data:
id id_type
1 1
2 1
3 2
4 3
5 3
6 3
有什么建议吗?
Expected Output :
6
5
But When I remove the limit ordering is not same :
5
6
4
3
2
注意:这只是一个示例数据结构。原来 table 包含很多字段和不同的列。
也许根本就没有问题。看到这个。
MariaDB [fbb]> SELECT * FROM `test`;
+----+---------+
| id | id_type |
+----+---------+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 3 |
| 6 | 3 |
+----+---------+
6 rows in set (0.00 sec)
MariaDB [fbb]> SELECT DISTINCT(id) FROM `test` WHERE (1 AND id_type!=1) ORDER BY id desc LIMIT 2;
+----+
| id |
+----+
| 6 |
| 5 |
+----+
2 rows in set (0.00 sec)
MariaDB [fbb]>
我正在使用下面的查询,在 where 和 limit 中使用 not 运算符。我无法获得正确的数据排序(没有限制子句是不同的,并且数据的限制排序是不同的)。
SELECT DISTINCT(id) FROM `table` WHERE (1 AND id_type!=1) ORDER BY id desc LIMIT 2
Table Structure with sample data:
id id_type
1 1
2 1
3 2
4 3
5 3
6 3
有什么建议吗?
Expected Output :
6
5
But When I remove the limit ordering is not same :
5
6
4
3
2
注意:这只是一个示例数据结构。原来 table 包含很多字段和不同的列。
也许根本就没有问题。看到这个。
MariaDB [fbb]> SELECT * FROM `test`;
+----+---------+
| id | id_type |
+----+---------+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 3 |
| 6 | 3 |
+----+---------+
6 rows in set (0.00 sec)
MariaDB [fbb]> SELECT DISTINCT(id) FROM `test` WHERE (1 AND id_type!=1) ORDER BY id desc LIMIT 2;
+----+
| id |
+----+
| 6 |
| 5 |
+----+
2 rows in set (0.00 sec)
MariaDB [fbb]>