Gus
Gus

Reputation: 1923

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.

Upvotes: 3

Views: 10137

Answers (1)

flesk
flesk

Reputation: 7579

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.

Upvotes: 16

Related Questions