Code:
$query='SELECT DISTINCT session.userid,user.username FROM session LEFT JOIN user ON user.userid=session.userid WHERE user.invisible=0 AND session.userid>0 AND ('.time().'-session.lastactivity-1500)<0 ORDER BY user.username';
The 1500 is the timeoutvalue of your cookies, you should set this to match your board setting (or get it from the option table in a seperate query).
Access table has nothing to do with who is online.
When you have more than one table in your query use JOIN to join them or you might get too many results back.
Use distinct keyword to only get unique results.