简体   繁体   中英

SQL query error unknown column in SELECT + JOIN +

This is my SQL code (using phpmyadmin simulator) :

SELECT user_activity.user_ip,user_activity.id,user_activity.post_id , posts.id
FROM  user_activity,users 
INNER JOIN posts ON user_activity.post_id = posts.id
WHERE user_activity.user_id = users.id and users.forgen_note = 'test note'; 

And it respons an error:

MySQL said: Documentation

#1054 - Unknown column 'user_activity_now.stream_id' in 'on clause'

How can I fix it please?

Don't mix join syntax:

SELECT user_activity.user_ip,user_activity.id,user_activity.post_id, posts.id
FROM user_activity
    INNER JOIN users ON user_activity.user_id = users.id
    INNER JOIN posts ON user_activity.post_id = posts.id
WHERE users.forgen_note = 'test note'; 

Generally you should avoid using comma joins. It's harder to read and is less expressive overall about what you're doing.

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