SQL custom limit
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
精彩评论