SELECT t2.id AS id, count(t1.id) AS nb FROM table2 t2, table1 t1 WHERE t1.id = t2.id GROUP BY t2.id ORDER BY t2.id ASC;
SELECT t1.id AS id, count( id_table1 ) AS total FROM table1 t1, table2 t2 WHERE t1.id = t2.id_table1 GROUP BY t1.id ORDER BY t1.id ASC
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiontable1 id_t1 title 1 cat1 2 cat2 3 cat3 4 cat4 5 cat5 table2 id_t2 id_t1 name 1 1 item1 2 1 item2 3 2 item3 4 1 item4 5 3 item5 6 4 item6 7 4 item7 8 2 item8
SELECT t1.id_t1, COUNT(t2.id_t1) AS total FROM table1 t1 LEFT JOIN table2 t2 ON t1.id_t1 = t2.id_t1 GROUP BY t1.id_t1
id_t1 total 1 3 2 2 3 1 4 2 5 0
SELECT t1.id, COUNT( t2.id_table1 ) AS total FROM table1 t1 RIGHT JOIN table2 t2 ON t1.id = t2.id_table1 GROUP BY t1.id
SELECT ..... FROM table1, TABLE2