sql – Select first name? – Select in the bank


I have a table with the following names:

João Goldy Alfredo, Gaby, João Antônio, Rodrigo, Maria Aparecida, Mario

How can I get only their first name, and those who don't have a last name, should show it anyway.

what i tried:


but with that I was only able to get the first name of those who have a surname, since Gaby, Rodrigo and Mario do not appear in the select. Is there any way to return the first name of those with a surname and show those who do not have a surname?


As I understand it, you only want to show the name of all players right? Resulting something like this:


If so, first of all, you need to standardize the string, that is, we have space before comma, comma after space.

REPLACE(REPLACE(nomejogador,', ',','),' ,',',')

Then we use regular expression to extract just the names:


(read: Find the space, find everything that was between that space and the first comma you find.)

So we have the query:

SELECT REGEXP_REPLACE(REPLACE(REPLACE(nomejogador,', ',','),' ,',',')
  FROM jogador
Scroll to Top