Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select part of table column data in mysql

Tags:

mysql

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

like image 914
Kim Avatar asked May 11 '12 12:05

Kim


People also ask

How do I select a specific record in MySQL?

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.

How do I select a specific column from a table in MySQL?

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?

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.


1 Answers

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.

like image 91
Pablo Avatar answered Sep 23 '22 01:09

Pablo