开发者

SQLite in iPhone:I want to Retrieving 1 row for each date from sqlite

开发者 https://www.devze.com 2022-12-20 04:51 出处:网络
i only want to know that whether data is available for any specific date or not.If there are more than one data with the same date, i do not want to fetch all the data.I try to use

i only want to know that whether data is available for any specific date or not.If there are more than one data with the same date, i do not want to fetch all the data.I try to use LIMIT 0,1 in where clause but it means it will fetch total 1 data for the given date range. So please tell me the way to fetc开发者_开发百科h data between a date range with 1 data for particular date.

Thanks.


Very simple example:

CREATE TABLE(
name,
date
);

insert into events values ("foo", "2008-01-01");
insert into events values ("bar", "2008-01-01");
insert into events values ("goo", "2009-01-01");
insert into events values ("gai", "2009-01-01");
select max(name), date from events group by date;

Output:

foo|2008-01-01
goo|2009-01-01

See How to select the first/least/max row per group in SQL

0

精彩评论

暂无评论...
验证码 换一张
取 消