简体   繁体   中英

MYSQL Join - Unknown Column

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM