Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:21:09+00:00 2026-05-31T18:21:09+00:00

I have a MySQL table that has a field of comma separated values. How

  • 0

I have a MySQL table that has a field of comma separated values. How do I get the maximum value?

Example:

CREATE TABLE `test`.`scale` (`scale` VARCHAR(500));

INSERT INTO `test`.scale 
VALUES 
('1,5,0.3,0.8,1'), 
('0.5,0.7,0.1,0.3'), 
('7,0.5,0.7,4');

scale:

1,5,0.3,0.8,1
0.5,0.7,0.1,0.3
7,0.5,0.7,4

answer:

5
0.7
7

How do I select the max value in this string?

Unfortunately I can’t change the way the previous person implemented the comma separated solution. I hope there is a MySQL function that can help me out, otherwise I’ll have to do some messy PHP stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:21:10+00:00Added an answer on May 31, 2026 at 6:21 pm

    I don’t believe SQL has a function for splitting strings. Here’s some code that claims to do it, but I haven’t tested it.

    The deeper reason for this is that SQL desperately wants you to store your data in normalized form. In this particular case, this means that every field should represent a single piece of data about the subject of the row.

    Essentially you’d store scale and answer in two separate tables, which you could match with one another using an ID for the question each one belongs to. Scale would have one row per scale option, not one row per scale:

    OPTIONS                     ANSWERS
    question | scaleoption      question | answer
    ---------|------------      ---------|-------
           1 | 1.5                    1  | 5
           1 | .3                     2  | .7
           1 | .8               ... 
           1 | 1
           2 | .5
           2 | .7
    ...
    

    You could then use the query select max(scaleoption) from options where question = 2 to get the maximum option for question 2. This format also lets you do things like find all questions where one of the options is 1, or get a count of how many options a particular question has. It looks more complicated but it’s a flexible, extendible, portable way to do things.

    If you want to use your current format, you’ll have to return the entire string and break it up in some other programming language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field in my mysql table that I want to update. Example:
I have a MySQL database table that has a VARCHAR field storing a date
I currently have a MySQL database with a table that has a field that
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
I have a table in MySQL that has 3 fields and I want to
I have mysql table that has a column that stores xml as a string.
Lets say I have a table in MySQL called articles, that has a column
I have a user table in my mysql database that has a password column.
I have a MySQL table that defines values for a specific customer type. |
I have a table in MySQL that has a primary key: mysql> desc gifts;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.