I am working with phpmyadmin. I have one table log in phpmyadmin. I would like to change a value in one column. If I add new value, it must show me Arbeitsplatz 1 instead of 1 in the Station column.
This is my log table. In the third column I would like to replace values for every new entry. For example, if the new value is 3 in station column, it should show me Arbeitsplatz 3 in the log table. If it is 4, then Arbeitsplatz 4 and so on.
How do I implement this?
You probably need to change the column datatype from integer to varchar first, then update that row:
update `log` set `Station` = CONCAT('Arbeitsplatz ', `Station`);
But first, back up that table just in case something fails...
Related
I have added a new column as "DateOrder" to my existing table called "orders" and I need to add (insert) data to the new column.
The only way I have found is using the "Update, Set, Where" syntax, however, it forces me to add values each by repeating the syntax.
I would appreciate if you help me how I can insert all my values at once.
Four rows only? Then use CASE WHEN in the SET clause:
update orders
set dateorder =
(
case id
when 1 then date '2018-10-13'
when 2 then date '2017-08-24'
when 3 then date '2019-01-11'
when 4 then date '2018-02-02'
end
);
Don't store dates as integers. Store them as dates as shown.
Initially, while creating the new column set a default value to it. And see if it has any binding with others. Then after you can directly insert new values to new records and update previous records just by update.
I have a MySQL table called settings. It has multiple columns, where every column is an item with a single value. So it has only one row and no id column. The design is final (I don't plan to add more columns).
How can I update the value in a single column (change one setting's value)?
What's the problem with using this --> http://dev.mysql.com/doc/refman/5.0/en/update.html
?
UPDATE table1 SET column1 = value
In case you have more than one row, you can add:
WHERE table1.column = matching_value;
making sure the match criteria is only the row you need.
to update a value of certain item column you must specify the row contains the value to be updated, since you don't have a primary key, you can depend on the nature of item values to act as row identifier and i don't recommend that.. the best way is to update your design and add column for the primary key
I have a table that has a number of columns. For each row, I'd like to select three columns (PAR_BOOK, PAR_PAGE, PAR_LINE) and concatenate the contents of those three columns into a new fourth column (APN).
So, if PAR_BOOK=0108, PAR_PAGE=291 and PAR_LINE=07, APN should be 010829107
Make sense?
But, I'm unsure of what query I should use to do this. I need the results stored back in the same table as it needs to be ultimately exported out as a csv to work with the program that's going to map the data.
Assuming your fourth column is already in the table, you would use the following update query:
UPDATE YourTable
SET APN = CONCAT(PAR_BOOK, PAR_PAGE, PAR_LINE)
If your fourth column is not present in the table yet, you should use the ALTER TABLE statement to add it first before running the UPDATE statement:
ALTER TABLE YourTable
ADD APN VARCHAR(256) NULL
Inserting into the same table with INSERT INTO ... SELECT ... is no problem at all. MySQL holds the selected rows in a temporary table.
I've just got a situation where i need to duplicate the unique
(auto-incremented) id of each new row in another column. So I was
wondering, instead of doing it the old fashioned way:
Insert row
Get insert_id
Update row with the insert_id
Can I tell MySQL to use the same value to which the new id is going
to be set, as a value for another column?
Something along the line of this:
INSERT INTO my_table(unique_column, id_duplicate)
VALUES('value', GET_UNIQUE_ID_OF_THIS() )
There's no way to accomplish what you're trying to accomplish using an auto-increment column in a single query.
Try approaching it from the other direction. Let's say your auto-increment column is id and your other column is called other_id. You could set the other_id column to allow NULL and simply set its value to NULL for the initial insert.
Then, when you query the value, simply do something like this:
SELECT id, IFNULL(other_id, id) AS other_id FROM mytable
The net result is the same. If you have something against NULL, you could also use 0 as the default value since auto-increment values start at 1.
A MySql 5.3 table with 100K rows has a primary key.
There is also an integer column which is not part of the key. I would like to update this column to contain a unique number for the table. E.g. for the first record it should contain 1, for the second 2 etc.
This could as well be an auto-increment column, but MySql does not allow auto-increment on non-key columns. I don't want this column to be part of the key, because of the way it gets populated from a file etc.
So how such a query would look like?
I don't know why do you want to do something like this, but a possible solution is this:
set #rownum:=0;
update <table> set column = #rownum:=rownum+1 order by <field>