Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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)
age_range=35-49
gender=Male
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):

age_range
35-49
45-55
25-35
... 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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Try this

select substring(custom_fields,instr(custom_fields,'gender')-7,5) as age_range from tbl;
share|improve this answer
    
Awesome, thanks! It took some tweaking but I managed to export them all. –  user1667063 Mar 29 '13 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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