I have a table 'photo' which contains 2000 entries. That table has a column called photo_note
which contains data in the format below but with different magnification value.
Magnification 30x. The resolution varies depending on.....
I need to select the rest of the column data starting with 'The resolution' and append it in another field 'photo_note_2'
Any suggestion how to do this in mysql is most appreciated
MySQL SELECT specific rows When a user wants to retrieve some individual rows from a table, a WHERE clause has to be added with the SELECT statement immediately followed by a condition. Here * indicates all columns.
If you want to retrieve the data from every column in a table, you do not need to specify each column name after the SELECT keyword. Use the asterisk character (*) in place of a column list in a SELECT statement to instruct MySQL to return every column from the specified table.
How can you retrieve a portion of any column value by using a select query in MySQL? SUBSTR() function is used to retrieve the portion of any column.
SUBSTRING
lets you return part of a string. INSTR
returns the position of a string in other string.
If you know that all the columns will have 'The resolution', then:
SELECT SUBSTRING(photo_note, INSTR(photo_note, 'The resolution')) from table;
If you know that all will have a 'x. ' before the string you want to retrieve, then
SELECT SUBSTRING(photo_note, INSTR(photo_note, 'x. ') + 3) from table;
You can see all the string functions for mysql here.
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