0

I am getting syntax error in following statement...but I want to use it by USING STATEMENT.

SELECT user_job.level1,user_job.tab_level,job.money_gain,job.exp_gain,job.energy_required,job.name,job_tem.no LEFT JOIN job USING(job_id) AND LEFT JOIN job_item USING(job_id)

job_id is common in all the tables.

1
  • 3
    can you split the query on multiple lines, run it again and post the syntax error? Commented Jun 25, 2010 at 9:07

3 Answers 3

2

First of all you're missing the FROM in the statement, so mysql knows from which table you're selecting. I'm assuming you're selecting from user_job table since this table is mentioned first in your select statement.

Second there must be no AND between multiple joins.

So you're complete and correct SQL statement should look like this:

SELECT
  user_job.level1,
  user_job.tab_level,
  job.money_gain,
  job.exp_gain,
  job.energy_required,
  job.name,
  job_tem.no
FROM user_job
LEFT JOIN job USING(job_id)
LEFT JOIN job_item USING(job_id)
Sign up to request clarification or add additional context in comments.

Comments

1

You are certainly missing FROM. The query could look like this.

SELECT user_job.level1,
  user_job.tab_level,
  job.money_gain,
  job.exp_gain,
  job.energy_required,
  job.name,
  job_tem.no 
FROM job 
  LEFT JOIN user_job USING(job_id)
  LEFT JOIN job_item USING(job_id)

1 Comment

Same answer as Daj pan Spokoj
1

You are missing the FROM-clause and as other have pointed out, you don't chain Joins with ANDs.

5 Comments

this is not an answer it should be comment
How is it not a valid answer to this question?
because it's a question itself, and it doesn't solve his problem.
So missing the from clause doesn't cause syntax errors? Anyways I'll change it to be an answer.
it does cause on error, but he would have still gotten a syntax error after adding the FROM, because - like you've written now - there was an AND too much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.