Mysql – Altering column data SQL

database-designMySQL

I have a set of car data, one of the columns represents the registration year. I want to change this column to age. As the data is from 2010 I assume that the following statement should calculate the age but there is an error?

Select Model, Variant, EngineSize, RegYear, Mileage, Price, Sector from   sampledata
update sampledata
set RegYear = 2010 - RegYear
where sector = 'Van Derived Cars'
and mileage > 200
and regyear != -1
and price != 999999

Can someone please help. I feel this should be very easy to do but everything I try seems to fail!

Best Answer

Error code 1064 :

This means you have an error in your SQL syntax.( ; missed)

 Select Model, Variant, EngineSize, RegYear, Mileage, Price, Sector 
 from sampledata ;
 update sampledata
 set RegYear = 2010 - RegYear
 where sector = 'Van Derived Cars'
 and mileage > 200
 and regyear != -1
 and price != 999999;

Mysql error code 1175 :

If you are in a safe mode, you need to provide a key (ex. primary key) in the where clause or you can SET SQL_SAFE_UPDATES = 0;