Estoy tratando de entender cómo hacer una subconsulta adecuada, no tiene sentido para mí, digamos que tengo dos tablas, books y chapters :
Libros
+----+------------------+----------+---------------------+ | id | name | author | last_great_chapters | +----+------------------+----------+---------------------+ | 1 | some book title | john doe | 2 | | 2 | foo novel title | some guy | 4 | | 3 | other book title | lol man | 3 | +----+------------------+----------+---------------------+Capítulos
+----+---------+----------------+ | id | book_id | chapter_number | +----+---------+----------------+ | 1 | 1 | 1 | | 2 | 1 | 3 | | 3 | 1 | 4 | | 4 | 1 | 5 | | 5 | 2 | 1 | | 6 | 2 | 2 | | 7 | 2 | 3 | | 8 | 2 | 4 | | 9 | 2 | 5 | | 10 | 3 | 1 | | 11 | 3 | 2 | | 12 | 3 | 3 | | 13 | 3 | 4 | | 14 | 3 | 5 | +----+---------+----------------+¿Cómo puedo unir las dos tablas y simplemente imprimir el número de filas (límite ordenado (last_great_chapters)) de los "last_great_chapters" de la lista de la tabla de libros para cada libro?
si lo entendí correctamente, ¿quiere imprimir los libros de tablas y el recuento de last_great_chapters en la tabla de capítulos?
si es así, inténtalo
select b.id, b.name, b.author , b.last_great_chapter, COUNT(c.chapter_number) as rownumbers FROM Books as b LEFT JOIN Chapters AS C ON c.chapter_number = b.last_great_chapters group by b.id, b.name, b.author , b.last_great_chapter