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