add +1 to column value in mySQL

How would I add +1 value to an existing column value in my table? Feel like this is a easy question but I haven't done it for a while and forgot the syntax to do so.

I tried...

UPDATE user_projects
SET views = views + 1    

Didn't work.

Thx for the help!
brihol44Asked:
Who is Participating?
 
sajaycConnect With a Mentor Commented:
Hi,
You only need the quotes around the variable if it is a string.  ID values are usually integers so you can insert without the quotes.  Can you try the query below?

UPDATE user_projects
SET views = views + 1  
WHERE project_ID = #project_ID#

0
 
sajaycCommented:
You query looks fine, the only thing I can think of if its not working is that views is a reserved word.
Therefore you need to put [ ] brackets around the field name.

E.g
UPDATE user_projects
SET [views] = [views] + 1    

Can you try this and see if it works?
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I believe that without a WHERE clause to limit it, you are going to add 1 to 'views' in every row in that table.
0
 
brihol44Author Commented:
Good catch... I didn't copy the complete query statement on accident...

I tried the above solution and that didn't work. Any other thoughts?

UPDATE user_projects
SET views = views + 1  
WHERE project_ID = '#project_ID#'

Thx,

Brian
0
 
brihol44Author Commented:
My IDs are like so... B690F14E-08-08-11... So I do need the quotes. Looks like everything is working though now. I'll give everybody equal points.

Thank you!
0
All Courses

From novice to tech pro — start learning today.