MySQL substring_index Delete Everything In Field After Space

I have a table called subscribers with a name field that contains data like this:

Tom Jones

Drew Brees

Tom Brady III

I need to delete everything after the first space for each record so that it looks like:

Tom

Drew

Tom

Using this question, I assembled the following query:

select substring_index(name,’ ‘,1) as deleteAllAfterSpace from subscribers

I get the following error:

Current selection does not contain a unique column.

When I run: SELECT * FROM subscribers WHERE INSTR(name, ‘ ‘) > 0

I do get the values I’m looking for as described.

I can assure you, name column is unique? What am I doing wrong?

Answer

SELECT name, subString(name, 1, POSITION(' ' IN name)) as deleteAllAfterSpace 
FROM subscribers;

Here is all you n

Leave a Reply

Your email address will not be published. Required fields are marked *