D_Pavel
Новичок
select
( select
count( messages2.text )
from `messages` as messages2 where messages2.parent = zz.key) count,
( select
SUBSTR( max( CONCAT( messages2.datetime, messages2.nik ) ) , 20 )
from `messages` as messages2 where messages2.parent = zz.key) lastnik,
zz.*
FROM
(
SELECT
topics.key,
t2.lentitle,
topics.nik ts,
topics.datetime topicdate,
topics.title
FROM `topics`
JOIN `messages` ON messages.parent = topics.key
AND messages.nik = 'Admin',
(
SELECT max( CHAR_LENGTH( title ) ) lentitle
FROM topics JOIN `messages` ON messages.parent = topics.key
AND messages.nik = 'Admin'
) AS t2
GROUP BY topics.key
ORDER BY topics.datetime DESC
LIMIT 40)zz
( select
count( messages2.text )
from `messages` as messages2 where messages2.parent = zz.key) count,
( select
SUBSTR( max( CONCAT( messages2.datetime, messages2.nik ) ) , 20 )
from `messages` as messages2 where messages2.parent = zz.key) lastnik,
zz.*
FROM
(
SELECT
topics.key,
t2.lentitle,
topics.nik ts,
topics.datetime topicdate,
topics.title
FROM `topics`
JOIN `messages` ON messages.parent = topics.key
AND messages.nik = 'Admin',
(
SELECT max( CHAR_LENGTH( title ) ) lentitle
FROM topics JOIN `messages` ON messages.parent = topics.key
AND messages.nik = 'Admin'
) AS t2
GROUP BY topics.key
ORDER BY topics.datetime DESC
LIMIT 40)zz