C
C
cats_wrath2021-09-19 18:15:47
SQL
cats_wrath, 2021-09-19 18:15:47

Display only first name from table field that says "First Name Last Name"?

In the database, the names and surnames of all family members (table FamilyMembers) are stored in the format "first name last name" (field member_name). It is necessary to separate them and display only the names.

I did it like this:
SELECT SUBSTRING(member_name, 1, LOCATE(' ', member_name)) as firstName FROM FamilyMembers

However, for some reason, this is not correct. Help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cats_wrath, 2021-09-19
@cats_wrath

Ah, I understand. Remove the space at the end:
SELECT SUBSTRING(member_name, 1, LOCATE(' ', member_name)-1) as firstName FROM FamilyMembers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question