remy
remy

Reputation: 1315

mysql: how to limit to query?

I select records and group them by date and uid(which is not the primary key), and I need to page those records by date, how can I do it?
For example:

uid  date
1    2012-01-10
2    2012-01-10
3    2012-01-09
3    2012-01-09
3    2012-01-11

sql:

SELECT date, uid
FROM users
GROUP by date,`uid` 

Results:

uid   date
1    2012-01-10
2    2012-01-10
3    2012-01-09
3    2012-01-11

Because I need to page those record by date, if I use sql like:

SELECT date, uid
FROM users
GROUP by date,`uid`
LIMIT 0,2

then I just get the records like this:

uid   date
1    2012-01-10
2    2012-01-10

. how can I page the record by date. The results I want when page size is 2:

uid   date
1    2012-01-10
2    2012-01-10
3    2012-01-09

Upvotes: 0

Views: 68

Answers (1)

Willem T
Willem T

Reputation: 104

SELECT date, uid
FROM users
WHERE date >= 'your date'
  AND date < 'your date' LIMIT 0, 3

Upvotes: 1

Related Questions