开发者

SQL custom limit

开发者 https://www.devze.com 2023-03-16 07:49 出处:网络
I have a calendar application, so I have 开发者_JS百科a table called events with the columns title and startDate. The thing is I want to select the events that are occuring during and after a specifie

I have a calendar application, so I have 开发者_JS百科a table called events with the columns title and startDate. The thing is I want to select the events that are occuring during and after a specified date.

SELECT *
FROM events
WHERE startDate >= date
ORDER BY startDate ASC, title ASC

That's the easy part. Now to the harder part. I want to make a limit to just select the 7 first dates that have events on it. How do I do that?


    SELECT *
    FROM events
    WHERE startDate IN (select distinct startdate from events order by startdate desc limit 0,7)
   AND startDate >= date
    ORDER BY startDate ASC, title AS


Use limit:

SELECT *
FROM events
WHERE startDate >= date
ORDER BY startDate ASC, title ASC
LIMIT 0,7

If you want just to retrive the first 7 dates:

SELECT distinct startDate
FROM events
WHERE startDate >= date
ORDER BY startDate
LIMIT 0,7
0

精彩评论

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