tags:

views:

23

answers:

2

i would like to get all the characters in a field before the blank

if field1 = "chara ters"

i want it to return chara

what would this select statement look like?

+2  A: 

You would need some string operations for that. Assuming every field has at least one space character:

SELECT SUBSTR(field1, 0, LOCATE(' ', field1)) FROM your_table;

Safe approach:

SELECT IF(
    LOCATE(' ', field1),
    SUBSTR(field1, 0, LOCATE(' ', field1)),
    field1
) FROM your_table;
soulmerge
+1 for safe version, although it's not clear what result should be returned when field does not contain a blank.
Mchl
+3  A: 

SELECT LEFT(field1,LOCATE(' ',field1))

Mchl
+1 didn't know about `LEFT`
soulmerge