|
|
|
|
|
для: cheops
(31.03.2014 в 07:21)
| | Результат: сортировка тредов по дате последнего добавленного в него сообщения
Сейчас: сообщения идут в разнобой.
Пока решил сортировкой полученного результата на РНР | |
|
|
|
|
|
|
|
для: mihdan
(27.03.2014 в 13:14)
| | Вообще должно бы... а в чем выражается "не пошло"? Какой результат хотели получить и что получается? | |
|
|
|
|
|
|
| Сообщения:
CREATE TABLE IF NOT EXISTS `messages` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`thread_id` bigint(20) NOT NULL,
`sender_id` bigint(20) NOT NULL,
`subject` varchar(200) NOT NULL,
`message` longtext NOT NULL,
`date_sent` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `sender_id` (`sender_id`),
KEY `thread_id` (`thread_id`)
);
|
Получатели сообщений:
CREATE TABLE IF NOT EXISTS `messages_recipients` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`thread_id` bigint(20) NOT NULL,
`unread_count` int(10) NOT NULL DEFAULT '0',
`sender_only` tinyint(1) NOT NULL DEFAULT '0',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `thread_id` (`thread_id`),
KEY `is_deleted` (`is_deleted`),
KEY `sender_only` (`sender_only`),
KEY `unread_count` (`unread_count`)
);
|
Пробовал так примерно:
SELECT r.thread_id
FROM messages AS m
JOIN messages_recipients AS r
USING(thread_id)
WHERE
r.user_id = 5 AND
r.is_deleted = 0
GROUP BY r.thread_id
ORDER BY m.date_sent desc
|
Не пошло) | |
|
|
|
|