Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add to each row in MySQL?

Tags:

sql

mysql

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?

like image 423
erotsppa Avatar asked Jun 19 '10 04:06

erotsppa


People also ask

What command do you use to add rows to a table?

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.

How can I add value in one column in MySQL?

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.

How do I add a second row in MySQL?

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.


1 Answers

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

like image 198
HorusKol Avatar answered Oct 21 '22 22:10

HorusKol