我正在使用如下所示的查询,其中没有运算符和限制。我无法获得正确的数据排序(没有限制子句它是不同的,数据的限制排序是不同的)。
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
注意:这只是一个示例数据结构。原始表包含许多字段和不同的列。
也许根本没有问题。看到这里。
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]>