Query to have only the names of records

5

I need a query that shows me a table name in which are last names and names separated by a comma example:

Martinez Nutero, Juan Alberto

and I need you to only show me the value from the comma. I tried this query but it does not work for me. Can someone help me please?

 select right(nombre,select locate(',',nombre) from asd_personas) from asd_personas
    
asked by Cris Valdez 14.09.2016 в 22:56
source

1 answer

5

You can use SUBSTRING_INDEX for what you need, try this:

SELECT SUBSTRING_INDEX(nombre, ',', 1) as nombre,SUBSTRING_INDEX(nombre, ',', -1) as apellido FROM asd_personas
    
answered by 14.09.2016 / 23:41
source