I have 5 tables in my DB: user, log1, log2, log3 and log4. Each log saves data about the user (log1 is logins log, etc.) - each log has UserID and CreateTime and LogID as his columns.
I want to create a query that is fast enough, that will show me the number of times each log has this user id. something like:
select u.UserID, Count(log1.CreateTime) as l1, ... Count(log4.CreateTime) as l4
from users u left join log1 on log1.UserID = u.UserID left join ...
group by u.UserID
The problem is that this query take too much time.
Can anyone help me optimize my query?