Reputation: 359
I am exploring MYSQL joins and I'm hoping you guys can help. I am trying to display users online from a sessions table. I want to join this up with my users table to find out if the user has a banned display group.
I am trying to stop banned users from appearing in queries
This is my code
$result = $db->query("SELECT * FROM `sessions` INNER JOIN `users` ON sessions.user_id=users.id WHERE sessions.user_id !='0' GROUP BY `sessions.user_id` ORDER BY id DESC LIMIT $start, $perpage");
I am receiving the following error:
MySQL Error: Unknown column 'sessions.user_id' in 'group statement'
The current where clause is to stop blank/old sessions from appearing (I have not added a where clause for the users table as of yet)
Any help would be much appreciated.
Upvotes: 0
Views: 42
Reputation: 1270401
You have written:
GROUP BY `sessions.user_id`
This is looking for a column with the name of "sessions.user_id" in one of the tables, including the single .
in the name.
You intend:
GROUP BY `sessions`.`user_id`
But why bother with the backticks:
GROUP BY sessions.user_id
Upvotes: 3