I have table ( users )
and I have another table let’s say (books)
users table :
Id | Username
1 :: john
2 :: doe
books table:
id | book_title | user_id(user who own this book)
1 :: book1 :: 2
2 :: book2 :: 2
3 :: book3 :: 2
4 :: book4 :: 1
5 :: book5 :: 1
Now , how can I get list of users and get how many books every user have
like this :
-
john ( 2 books )
-
doe ( 3 books )
I use codeigniter framework ..
thanks in advance 🙂
To answer your second question:
I just had to do this for some of my own analytics:
If you have to do this frequently, you might want to figure out how to do this using multiple joins which are more efficient than subqueries.