Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql like query that ignore the first word completely

Tags:

php

mysql

mysqli

I want the sql like query that ignores the first word from the field completely, I want remaining word.

For example: Name:
John Smith
ABC XYZ PQR

Output :
Smith
XYZ PQR

I want the string after the first (whitespace)

Thanks in advance.

like image 649
Jimit Shah Avatar asked Nov 18 '25 11:11

Jimit Shah


2 Answers

Try this:

SELECT RIGHT(Name, LENGTH(Name) - LOCATE(' ', Name))
FROM mytable

Function LOCATE returns the position of the first occurrence of space inside the column (if any). Using RIGHT we can easily extract the part that comes right after this space occurrence.

like image 86
Giorgos Betsos Avatar answered Nov 20 '25 02:11

Giorgos Betsos


Just use it.

SELECT SUBSTRING(name, LOCATE(' ', name)+1) FROM mytable

*name = Field Name,

*mytable= Table Name

like image 43
MD. ABDUL Halim Avatar answered Nov 20 '25 03:11

MD. ABDUL Halim