We have a column that is a simple integer. We want to add to each row the value 10. How do we do it in sql for the MySQL database?
Actually we have another column that needs to do the same thing, and it is a date. We need to add a month to the date. How to do that?
Insert Command To add a new row, type the I line command in Cmd for any displayed row, and then press Enter to insert a new data entry line after the selected row.
First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
You need to use ORDER BY clause to get the second last row of a table in MySQL. The syntax is as follows. select *from yourTableName order by yourColumnName DESC LIMIT 1,1; To understand the above syntax, let us create a table.
Integers:
UPDATE table_name SET int_column_value = int_column_value + 10;
UPDATE table_name SET int_column_value = 10 WHERE int_column_value IS NULL;
Dates:
UPDATE table_name SET date_column_value = DATEADD(date_column_value, INTERVAL 1 MONTH);
More info: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_adddate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With