I'm an SQL beginner and I'm having trouble searching correctly for the answer to this question, although I'm sure that it's been asked before. I have an column in an SQL table that looks like this:

custom_fields (this is the column name)
how_heard=Other (All three of these values are in the same field)

Is there any way to reach inside of this field with an SQL statement to get the values individually? I'd like to make three lists of the individual values to export to CSV files in a vertical columns.

Basically, the result should be a column like (for each value):

... etc.

I've been trying:

SELECT custom_fields.age_range FROM arp3_cam WHERE 1

But this is obviously incorrect. I'd really appreciate any hints on how to filter for values inside the same field -- feel free to redirect me to an answer if this has already been asked somewhere else. Thanks!

EDIT: based on other posts I've been reading, this setup violates first normal form, however, I still need to extract the data, if possible. I definitely wish the values in "custom_fields" had been added as individual columns.

1 Answer 1


Try this

select substring(custom_fields,instr(custom_fields,'gender')-7,5) as age_range from tbl;
  • Awesome, thanks! It took some tweaking but I managed to export them all. Mar 29, 2013 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.