简体   繁体   中英

How to get the last row using MYSQL GROUP BY

have two tables, table sets and chapters with MySQL table:

Table Series

ID_SERIES

NAME

DESCRIPTION


Table Chapters

ID_CHAPTERS

ID_SERIES

VIDEO

DATE_CREATED


As I can group all the chapters by id and give me back that I return in the last chapter, that way I do this query ?

thanks for reading.

Looking at your last comment your SQL should look like this:

SELECT * 
FROM VIDEOS 
    LEFT JOIN CHAPTER ON VIDEOS.ID_VIDEO = CHAPTER.ID_VIDEO 
GROUP BY CHAPTER .ID_VIDEO 
ORDER BY CHAPTER.DATE_CREATED DESC 
LIMIT 1;

The LIMIT 1 makes the query return just 1 row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM