0
此查询不会返回我所期望的。为什么?Android SQLite3异常与DISTINCT?
表:
create table t
(
comment varchar(10),
id int
);
数据:
insert into t values ('C1', 1);
insert into t values ('C2', 2);
insert into t values ('C3', 3);
insert into t values ('C4', 4);
insert into t values ('C5', 5);
insert into t values ('C6', 6);
insert into t values ('C7', 7);
insert into t values ('C8', 8);
insert into t values ('C9', 9);
insert into t values ('C1', 10);
查询:
select distinct comment from t order by id desc limit 8;
其结果是:
C9
C8
C7
C6
C5
C4
C3
C2
当我离开DISTINCT时,我得到最后一行,但我想抑制重复。 我的解决方法返回正确的结果集:
select comment from t group by comment order by max(id) desc limit 8;
不过我很好奇,如果我的查询是无效的(T-SQL的例子并不在一个查询中同时允许一个DISTINCT和ORDER BY,除非该命令列是选择列表)?
不是一个真正的答案,但我会接受它作为唯一的答案。 – cdonner 2014-05-22 15:57:11