Search code examples
mysqlselectsizelimit

Set max string size for MySQL SELECT result


I want to limit the max size of a MySQL SELECT using PHP. I could some sort of iteration with PHP, but that would be less efficient. Is there a way I can set the maximum string size or byte size of something to return? Thanks.


Solution

  • What about

    SELECT SUBSTR(myString, 1, 10) as myString from myTable 
    

    EDIT:

    Then you want

    SELECT myString from myTable where length(myString) < 11
    

    You also have char_length and bit_length.