Answer the question
In order to leave comments, you need to log in
How to choose birthdays?
There is such a table - (date - birthday)
CREATE TABLE `birthday` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`date` datetime DEFAULT '0000-00-00 00:00:00',
`name` tinytext,
`photo` tinytext,
`description` tinytext,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=241 DEFAULT CHARSET=cp1251;
Answer the question
In order to leave comments, you need to log in
And there will be a lot of nuances. If, for example, seven people have birthdays today, which of them should be in the sample? And if all this is not taken into account, then it is easy
(SELECT *
FROM `birthday`
WHERE MONTH(`date`) > MONTH(CURDATE())
OR (MONTH(`date`) = MONTH(CURDATE())
AND DAYOFMONTH(`date`) = DAYOFMONTH(CURDATE()))
ORDER BY MONTH(`date`), DAYOFMONTH(`date`)
LIMIT 3)
UNION (SELECT *
FROM `birthday`
WHERE MONTH(`date`) = MONTH(CURDATE())
AND DAYOFMONTH(`date`) = DAYOFMONTH(CURDATE()))
UNION (SELECT *
FROM `birthday`
WHERE MONTH(`date`) < MONTH(CURDATE())
OR (MONTH(`date`) = MONTH(CURDATE())
AND DAYOFMONTH(`date`) < DAYOFMONTH(CURDATE()))
ORDER BY MONTH(`date`) DESC, DAYOFMONTH(`date`) DESC
LIMIT 3)
date between date_sub(now(), interval N day) and date_add(now(), interval N day)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question