· 9 years ago · Jan 02, 2017, 04:52 PM
1SELECT `tema`.*, (SELECT COUNT(*) FROM `post` WHERE `post`.`id_tema`=`tema`.`id`) AS `count_post`, (SELECT `id` FROM `post` WHERE `post`.`id_tema`=`tema`.`id` ORDER BY `id` DESC LIMIT 1) AS `id_post`, (SELECT `login` FROM `users` WHERE `users`.`id`=(SELECT `id_user` FROM `post` WHERE `post`.`id_tema`=`tema`.`id` ORDER BY `id` DESC LIMIT 1)) AS `login` FROM `tema` WHERE `id_forum`='4' ORDER BY `up` DESC, `time` DESC LIMIT 3260, 20
2
3--
4-- Структура таблицы `tema`
5--
6DROP TABLE IF EXISTS `tema`;
7CREATE TABLE IF NOT EXISTS `tema` (
8`id` int(11) NOT NULL auto_increment,
9`id_razdel` int(11) NOT NULL,
10`id_forum` int(11) NOT NULL,
11`id_user` int(11) NOT NULL,
12`name` varchar(500) NOT NULL,
13`translate` varchar(500) NOT NULL,
14`text` text NOT NULL,
15`time` int(11) NOT NULL,
16`up` enum('0', '1') NOT NULL default '0',
17`closed` enum('0', '1') NOT NULL default '0',
18`count` int(11) NOT NULL default '0',
19PRIMARY KEY (`id`),
20KEY `id_razdel` (`id_razdel`),
21KEY `id_forum` (`id_forum`),
22KEY `id_user` (`id_user`),
23KEY `time` (`time`),
24KEY `up` (`up`),
25FULLTEXT KEY `name` (`name`)
26) ENGINE=MyISAM DEFAULT CHARSET=utf8;
27
28--
29-- Структура таблицы `post`
30--
31DROP TABLE IF EXISTS `post`;
32CREATE TABLE IF NOT EXISTS `post` (
33`id` int(11) NOT NULL auto_increment,
34`id_razdel` int(11) NOT NULL,
35`id_forum` int(11) NOT NULL,
36`id_tema` int(11) NOT NULL,
37`id_user` int(11) NOT NULL,
38`text` text NOT NULL,
39`cit` int(11) NOT NULL,
40`time` int(11) NOT NULL,
41`timeedit` int(11) NOT NULL,
42`kedit` int(11) NOT NULL,
43`id_user_edit` int(11) NOT NULL,
44`vote` varchar(11) NOT NULL,
45PRIMARY KEY (`id`),
46KEY `id_razdel` (`id_razdel`),
47KEY `id_forum` (`id_forum`),
48KEY `id_tema` (`id_tema`),
49KEY `id_user` (`id_user`),
50KEY `time` (`time`),
51FULLTEXT KEY `text` (`text`)
52) ENGINE=MyISAM DEFAULT CHARSET=utf8;