This is my database layout:
- ID (int – unique primary key
- user (int) – foreign key for users I search by their
namecolum - starttime (timestamp) – session start time
- endtime (timestamp) – session end time
- idletime (int) – idle time in minutes
For example I want to know how many minutes a specific player was online.
The following query works fine. I get about 3443 minutes.
SELECT user,
SUM(TIMESTAMPDIFF(MINUTE,starttime,endtime)-idletime)
FROM gc_sessions
WHERE user = 139
But if I want to do this with joins I get 8 by using the following query.
SELECT name,
SUM(TIMESTAMPDIFF(MINUTE,starttime,endtime)-idletime)
FROM gc_sessions
JOIN gc_users ON gc_user.id = gc_sessions.id
WHERE name LIKE "variell"
What is wrong with my query?
Please try following query and tell me the result