views:

44

answers:

3

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  A: 

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

Maxem
this is not an answer it should be comment
jigfox
How is it not a valid answer to this question?
Maxem
because it's a question itself, and it doesn't solve his problem.
jigfox
So missing the from clause doesn't cause syntax errors? Anyways I'll change it to be an answer.
Maxem
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.
jigfox
+1  A: 

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)
Michał Pękała
this won't work either, what about the `user_job`-table?
jigfox
You're right. Thanks. I've corrected that.
Michał Pękała
Same answer as Daj pan Spokoj
Himadri
+2  A: 

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)
jigfox