How to solve the problem of data loss in multi-table join table query?

use leftJoin multi-table join lookup. Finally, a field in select is a field from count in one of the right tables, but if there is no count data in that table, the entire query will lose the result. Now you want to keep the data in the left table if there are no results in the query.

the code looks like this:

SELECT a.name,COUNT(b.id) AS com FROM `a` LEFT JOIN `b` ON `a`.`uid` = `b`.`uid` LEFT JOIN `c` ON `d`.`id` = `c`.`id`  ORDER BY `a`.`id` DESC LIMIT 10 OFFSET 0

finally, if there is no corresponding data in b, the query data will be lost

Nov.25,2021

try adding a gourp by a.name in front of order by

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-1e7e59d-9cd.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-1e7e59d-9cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?