MySql, Copy one column into another and add some text - mysql

I have a column which has an Article-ID and one empty with the picture filename. Example: The article with the ID 34.67 should get the filename 34.67.jpg and so on. There are about 20'000 articles.
What would be the best way to do this?

Depending on your table structure or SQL dialect - it will be something like this:
UPDATE Tablename SET filename=concat(articleid, '.jpg')

OK, Thank you very much. I ended up using following code. This worked like a charm.
UPDATE oxarticles SET OXPIC1=LOWER(concat(OXARTNUM, '.jpg')) WHERE OXPIC1 = ' '

Related

how to delete single record from list

I have a record in table column like this (1001,1002,1003,1004,1005)
and I want to delete "1003" from this list. Please help me.
For your own good, don't store data like this. This type of issue is not, by far, the biggest problem you will run into.
This being said, you can solve you issue by using:
UPDATE TABLE
SET COLUMN = REPLACE (COLUMN, ',1003,', ',')
WHERE ID = PK;
even this will work:
update tablename set column=(select
substr(column,1,instr(colname,',',2))||susbtr(column,instr(column,',',3),length(column)-
instr(column,',',3)) from tablename where id=value;

MySql - how to delete records based on a word?

I have no experience in database administration and I find myself in a situation where I have to bury it. I have a database in which I have several thousand records in the name of which is the word "Year_2014". I want to remove them
I tried to use the command but removes everything:
SELECT * FROM nkigz_flippingbook_pages WHERE checked_out = 'Year_2014';
DELETE FROM nkigz_flippingbook_pages WHERE checked_out LIKE 'Year_2014';
Can you tell me how can I deal with this problem?
Regards
Igor
Use % in LIKE.
Example:
SELECT * FROM nkigz_flippingbook_pages WHERE checked_out = '%Year_2014%';
Returns everything that has the expression: 'Year_2014'
Try this:
DELETE FROM nkigz_flippingbook_pages WHERE checked_out LIKE '%Year_2014%'
This command will delete whole row if it found "Year_2014"
DELETE FROM nkigz_flippingbook_pages WHERE checked_out like '%Year_2014%';
If you want to replace this word with blank space, you can use below command (this will not delete your row)
Update nkigz_flippingbook_pages set checked_out = ' ' WHERE checked_out ='Year_2014';
Hope this helps!

mysql add http:// to all records in website column

I'm almost done transferring/reconstructing a substantial mysql db for new application. Column 'website' shows 'www.example.com'. Because the new application reads it as a hyperlink, I need the column to read 'http://www.example.com'. Is there a way to add the 'http://' in the beginning of each record for that column? Thanks in advance!
You can use the CONCAT function to do that:
UPDATE tbl SET website=CONCAT('http://', website);
If you want to get cleverer and only update columns which don't already have http:// prepended, try
UPDATE tbl SET website=CONCAT('http://', website)
WHERE website NOT LIKE 'http://%';
Update
To prevent update to columns that have no site in them currently use this
UPDATE tbl SET website=CONCAT('http://', website)
WHERE website NOT LIKE 'http://%' AND website<>'';
You can use the concat command. Something like
SELECT CONCAT('http://', website) FROM table
Use concat to generate the new column:
UPDATE table1 SET website = CONCAT("http://", website);

Transfering data between one data base to another in SQL

I am trying to transfer a couple of columns from an old database to a live database.. The issue I have is that I need the columns to match up with a column on the live database. For instance let me use an example: My live database has a table like this
TABLE NAME is ITEMS Then inside the table there would be a columns name ItemLookUp and ExtensionDescription.
So the live table would look something like this:
**ItemLookUp** **ExtensionDesctiption**
AAA-06-201 'Blank'
BBB-08-201 'Blank'
CCC-99-201 'Blank'
The old database would look like this:
**ItemLookUp** **ExtensionDescription**
AAA-06-201 Toy part
BBB-08-201 Mechanic Part
CCC-99-201 2x1 Screw
So what I am trying to do is make the live database have the information of the old database, but the ExtensionDescription needs to match up with the ItemLookup meaning for example if the ItemLookUp is AAA-06-201 it must have an ExtensionDescription of Toy part... Any help would be greatly appreciated.
Try on this. I thik this will help you.
update tbnew
set tbnew.ExtensionDesctiption = tbold.ExtensionDesctiption
from tbold
where
tbnew.ItemLookUp = tbold.ItemLookUp
UPDATE dbnew.items a JOIN dbold.items b
ON a.ItemLookUp=b.ItemLookUp
SET a.ExtensionDescription=b.ExtensionDescription
Assuming same server.
Figure it out.. Thanks for all your help
update Item
set ExtendedDescription = X.ExtendedDescription
from Item I
INNER JOIN /old db name/raxx.dbo.Item X on I.ItemLookupCode = X.ItemLookupCode
WHERE I.ItemLookupCode = X.ItemLookupCode AND I.ExtendedDescription like ''

Changing column content in many rows

I have a column called code and in every row, the column contains FE. Because I do not want to go through 13,000 records, is there a quick way to replace FE inside 'code' with FEU?
While I appreciate this may be a simple question (or not?), I wasn't sure how to word it in order to find a solution.
You should be able to do like this:
UPDATE <table> SET code = REPLACE(code, 'FE', 'FEU');
If the column really just contains the value FE a simple WHERE clause should be enough:
UPDATE <table> SET code = 'FEU' WHERE code = 'FE';
Maybe something like this?
UPDATE yourtable
SET code = 'FEU'
WHERE code = 'FE'
This will work if your column contains only the string 'FE' and you want to replace it with 'FEU'.
update `table`
set `code` = replace(`code` , "FE","FEU")
where (if there is a where write it here)
should do you
This is probably the quickest way. You can try this:-
UPDATE yourtable
SET code = 'FEU'
WHERE code = 'FE'