CodeIgniter Forums
How to count the number of 02 tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to count the number of 02 tables (/showthread.php?tid=65667)



How to count the number of 02 tables - garidinh - 07-09-2016

Hi every body ?
I have 2 table data:
db_category: 

+idcate
+name
db_book:
+ idbook
+ name
+ idcate

Now I want to count the number by category. 

Example: 
Book 1: 2 file
Book 2: 5 file

Please help me, thanks Big Grin


RE: How to count the number of 02 tables - Paradinight - 07-10-2016

This makes no sense at all. Huh

example
Code:
SELECT
    category.name,
    count(book.id)
FROM
    category
INNER JOIN
    book
ON category.id = book.id
GROUP BY category.id

cat_a 12
cat_b 10