There are two tables in the database. First places places (idPlace, name, date) second comments - comments to it (id, autor, text). The task is to create a request that displays a list of establishments, counting the number of comments.

Made up such ...

 SELECT idPlace, name, date, COUNT(*) FROM places JOIN comments places.idPlace = comments.id GROUP BY idPlace 

... but the trouble is that comments are not for all establishments. And accordingly, they are not issued in the request. How to fix?

Ps Should I use such troubles or is it better to just insert another short request for the number of comments in a loop (in php)?

    1 answer 1

    dig in the direction of LEFT JOIN, read here http://blog.sergey-lysenko.ru/2011/12/inner-left-and-right-joins.html

    LEFT JOIN Returns all data from the “left” table, even if no match is found in the “right” table

    • Wow, thanks! - Zhenya Vedenin
    • if the answer came up, mark the answer as correct by checking the box next to the answer, it's not) - Boris Begun
    • "you can accept the correct answer only in 7 minutes" I wait) - Zhenya Vedenin
    • one
      a) well, it did not take into account) - Boris Pobezhimov