user3762090
user3762090

Reputation: 1

SQL command not properly ended when using a join

I'm trying to use a JOIN in my query and can't figure out why I'm getting a

SQL command not properly ended

error. Here's the query I'm trying to run:

select 
    v.contid, v.group_id, a.user_id 
from 
    application_users a, web_users v
where 
    a.is_active = 1
    and v.group_id in (22, 26, 595, 635)
    and a.user_id = v.user_id
join 
    contest_results cr on cr.user_id = a.user_id
where 
    cr.period = 201502

Upvotes: 0

Views: 1968

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93764

Thats not the right syntax to JOIN multiple tables.

Also don't use comma separated join always use proper INNER JOIN syntax which is more readable. Try this

SELECT v.contid, 
       v.group_id, 
       a.user_id 
FROM   application_users a 
       INNER JOIN web_users v 
               ON a.user_id = v.user_id 
       INNER JOIN contest_results cr 
               ON cr.user_id = a.user_id 
WHERE  cr.period = 201502 
       AND a.is_active = 1 
       AND v.group_id IN ( 22, 26, 595, 635 )

Upvotes: 4

Related Questions