mysql - SQL complaining about an existing field -


the following query attempts can expressed @users.courses (where @user.id = 1). i'm giving information i'm not sure if right since query doesn't run

select * courses courses.id =   courses_users.user_id , courses_users.user_id = 1 

sql complains:

#1054 - unknown column 'courses_users.user_id' in 'where clause'

i of these fields exist i'm not sure i'm doing wrong.

your where clause references courses_users, tables never appears in where or join clause.

you should either added from clause:

select *    courses, courses_users -- here!  courses.id = courses_users.user_id ,         courses_users.user_id = 1 

or, better yet, use explicit join clause:

select *    courses join   courses_users on courses.id = courses_users.user_id -- here!  courses_users.user_id = 1 

Comments