MySQL 5.
Table: schedule Columns: id int(10) UN PK AI startdate date groupid smallint(5) UN
The following statement extracts the Schedule ID for a given group (the schedule with the latest date not greater than the given date):
SELECT id FROM schedule WHERE groupid=@group AND @date>=startdate ORDER BY startdate DESC LIMIT 1
Question: Can I extract Schedule IDs for all groups, without enumerating (calling the above statement repeatedly) with all existing group IDs?
(groupid)
have a unique constraint? Or thatUN
means unsigned?groupid
,startdate
. There are no other unique constraints (not counting the primary key for ID)