0

Whats wrong with this query. I'm getting an error saying

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 'Item 1') where ItemName like 'Item 1' at line 1

My query is

insert into newitem (QuantityAvailable) values 
(Select count(*) from  addtoinventory where ItemName like 'Item 1') 
where ItemName like 'Item 1'
4
  • Why do you repeat your WHERE clause? Commented Jan 1, 2012 at 22:32
  • How logical is that an insert statement has a WHERE clause? Commented Jan 1, 2012 at 22:33
  • the first where clause is for the nested query. I'm counting all those rows with item name like "Item 1" and the second where clause is for the insert where I'm inserting into those rows (the output of nested query) where Item name like "Item 1" Commented Jan 1, 2012 at 22:34
  • What should be the best way to do this? Commented Jan 1, 2012 at 22:35

2 Answers 2

3

Take out the word values from your query.

Also, I don't see what you expect the where clause to do in the outer query. If you haven't inserted a value yet, how can you compare it to anything? If you have, then the inner where clause takes care of that.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm so sorry for asking this stupid question. I am still in a party mood.. I should use update newitem rather than insert into .. !!
0

insert into newitem (QuantityAvailable) Select count(*) from addtoinventory where ItemName like '%Item 1%'

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.