0

I am trying to write an sql that checks up multiple tables,this is what I got:

UPDATE item_template SET BuyPrice = 0, SellPrice = 1 WHERE entry IN (SELECT item FROM npc_vendor WHERE entry IN (SELECT entry FROM creature WHERE area = 3998)));

Now my error is:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

What may cause it?

6 Answers 6

1

As Dave Mroz mentioned, this query would be much more efficient if you used multi-table update syntax with JOIN, something like this:

UPDATE item_template 
  inner join npc_vendor on npc_vendor.item = item_template.entry
  inner join creature on creature.entry = npc_vendor.entry
SET item_template.BuyPrice = 0, item_template.SellPrice = 1 
where creature.area = 3998;
Sign up to request clarification or add additional context in comments.

1 Comment

Great,I just tested mine and it took more then 300 seconds to run.I am pretty novice into mysql :)
1

You have two opening ( and three closing )

Also, you should probably try to rewrite this with a JOIN instead of nested subqueries.

Comments

1

it should be

UPDATE item_template SET BuyPrice = 0, SellPrice = 1 WHERE entry IN (SELECT item FROM npc_vendor WHERE entry IN (SELECT entry FROM creature WHERE area = 3998));

1 Comment

Thank you,seems I have to drink another coffee.
1

I think you have 1 too many closing parens.

Comments

1

you have one extra closing paranthese

    UPDATE item_template
SET BuyPrice = 0,
    SellPrice = 1
WHERE entry IN
    (SELECT item
     FROM npc_vendor
     WHERE entry IN
         (SELECT entry
          FROM creature
          WHERE area = 3998));
                         ^^^^^^^ Remove one ) here

Comments

1
UPDATE item_template SET BuyPrice = 0, SellPrice = 1 WHERE entry IN (SELECT item FROM npc_vendor WHERE entry IN (SELECT entry FROM creature WHERE area = 3998));

this is correct.you have added extra ')'

Comments

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.