I want to show the conclusion of all users.
I have 3 tables.
column
post_id(index) user_id
1 1
2 3
3 3
4 4
photo table
photo_id(index) user_id
1 2
2 4
3 1
4 1
desktop video
photo_id(index) user_id
1 4
2 4
3 3
4 3
and in user table
user_id(index) user_name
1 mark
2 tommy
3 john
4 james
in fact, it has more than 4 rows for each table.
I want to get the result as follows.
id name post photo videos
1 mark 1 2 0
2 tommy 0 1 0
3 john 2 0 2
4 james 1 1 2
5 .. .. .. ..
Below is the SQL code that may work correctly, but very slowly, I would appreciate it if you could help me how it uses LEFT JOINit. Thank you
SQL
"select user.*,
(select count(*) from post where post.userid = user.userid) postCount,
(select count(*) from photo where photo.userid = user.userid) photoCount,
(select count(*) from video where video .userid = user.userid) videoCount
from user order by user.id"
(or ORDER BY postCount, photoCount or videoCount ASC or DESC as I want)
I researched before, but no one helped me.
source
share