Mysql query questions, according to the latest published articles or the latest comments to query the information of the first few users.

tb_user (user information) id
tb_article (article information) id, foreign key user_id-> tb_user.id
tb_comment (comment information) id, foreign key user_id-> tb_user.id
query the top 5 users of the latest article or comment.
order by tb_article.create_time desc, tb_comment.create_time desc

The

question arises: how do you write this SQL without having a performance impact and meeting the requirements at the same time?

Feb.28,2021

//  
select tb_user.* from tb_article join tb_user on tb_user.id=tb_article.id order by tb_article.create_time desc limit 5;
//?...233.....
SELECT
    a.uid,
    username
FROM
    (
        (
            SELECT
                `uid`,
                `create_time` AS `time`
            FROM
                tb_article
        )
        UNION ALL
            (
                SELECT
                    `uid`,
                    `create_time` AS time
                FROM
                    tb_comment
            )
    ) AS a
JOIN tb_userAS b ON a.uid = b.uid
GROUP BY
    a.uid
ORDER BY
    a.time DESC
LIMIT 5
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf89e7-30e58.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf89e7-30e58.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?