在LEFT JOIN上显示最后一个输入

时间:2016-10-10 08:43:17

标签: php sql pdo

以下是我的问题,如何在(?:...)内获取topic_id = 27

另一个“新”主题,如cat_id = 2

感谢所有人,对不起我的不知情和我的英语: - )

Result in HTML ][DataBase] Code

ID = 24

1 个答案:

答案 0 :(得分:0)

SQL查询

SELECT
    categories.*,
    (SELECT topics.topic_subject
     FROM topics
     WHERE topics.topic_cat = categories.cat_id
     ORDER BY topics.topic_date DESC
     LIMIT 1) AS category_last_subject
FROM 
    categories
ORDER BY 
    categories.cat_id DESC
LIMIT 5