Reputation: 3346
i need to select only the first name (that is the first word) of the user.
For example, Andy Jones, only select Andy
Any idea?
thanks
Upvotes: 6
Views: 11176
Reputation: 42093
If I understand, your FirstName and LastName are in one column. You can achieve this using user defined functions.
Example:
SELECT SPLIT_STR(name, ' ', 1) as firstname FROM users;
Read following post for more options:
Upvotes: 1
Reputation: 4423
Take a look at substring_index.
select substring_index(field, " ", 1) ....
Upvotes: 22
Reputation: 1246
For something like this you would normally put the first and last name in their own columns. If you cannot, then you can get the index of the first space, then substring(0,index of the first space). I would really recommend though that you split that into two columns, if you can.
Upvotes: 0